0
0
Rubyprogramming~10 mins

Block syntax (do..end and curly braces) in Ruby - Interactive Code Practice

Choose your learning style9 modes available
Practice - 5 Tasks
Answer the questions below
1fill in blank
easy

Complete the code to print numbers using a block with curly braces.

Ruby
5.times [1] puts "Hello" [2]
Drag options to blanks, or click blank then click option'
A( )
Bdo end
C{ }
D[ ]
Attempts:
3 left
💡 Hint
Common Mistakes
Using do..end instead of curly braces for single-line blocks.
Using parentheses instead of block delimiters.
2fill in blank
medium

Complete the code to print numbers using a block with do..end syntax.

Ruby
3.times [1] puts "Hi" [2]
Drag options to blanks, or click blank then click option'
Ado end
B{ }
C( )
D[ ]
Attempts:
3 left
💡 Hint
Common Mistakes
Using curly braces for multi-line blocks.
Using parentheses instead of block delimiters.
3fill in blank
hard

Fix the error in the block syntax to correctly print each number.

Ruby
4.times [1] |i| puts i [2]
Drag options to blanks, or click blank then click option'
A{
B(
C[
Ddo
Attempts:
3 left
💡 Hint
Common Mistakes
Using { without the matching }.
Using parentheses instead of block delimiters.
4fill in blank
hard

Fill both blanks to create a block that prints squares of numbers.

Ruby
5.times [1] |n| puts n[2]2 [3]
Drag options to blanks, or click blank then click option'
Ado
B**
Cend
D*
Attempts:
3 left
💡 Hint
Common Mistakes
Using * instead of ** for exponentiation.
Forgetting to close the block with end.
5fill in blank
hard

Complete the code to create a block that prints doubled numbers using curly braces.

Ruby
3.times { |x| puts x [1] 2 }
Drag options to blanks, or click blank then click option'
A{
B*
C}
D**
Attempts:
3 left
💡 Hint
Common Mistakes
Using ** instead of * for multiplication.
Forgetting to close the block with }.