Practice - 5 Tasks
Answer the questions below
1fill in blank
easyComplete 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'
Attempts:
3 left
💡 Hint
Common Mistakes
Using do..end instead of curly braces for single-line blocks.
Using parentheses instead of block delimiters.
✗ Incorrect
In Ruby, blocks with curly braces use { } syntax for single-line blocks.
2fill in blank
mediumComplete 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'
Attempts:
3 left
💡 Hint
Common Mistakes
Using curly braces for multi-line blocks.
Using parentheses instead of block delimiters.
✗ Incorrect
The do..end syntax is used for multi-line or more readable blocks in Ruby.
3fill in blank
hardFix 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'
Attempts:
3 left
💡 Hint
Common Mistakes
Using { without the matching }.
Using parentheses instead of block delimiters.
✗ Incorrect
The do keyword starts a block that can take parameters like |i| in Ruby.
4fill in blank
hardFill 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'
Attempts:
3 left
💡 Hint
Common Mistakes
Using * instead of ** for exponentiation.
Forgetting to close the block with end.
✗ Incorrect
Use do to start the block, ** for exponentiation, and end to close the block.
5fill in blank
hardComplete 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'
Attempts:
3 left
💡 Hint
Common Mistakes
Using ** instead of * for multiplication.
Forgetting to close the block with }.
✗ Incorrect
Use { and } to start and end the block, and * to multiply x by 2.