Practice - 5 Tasks
Answer the questions below
1fill in blank
easyComplete the code to print a string with a newline using puts.
Ruby
puts [1] Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Using print instead of puts
Forgetting quotes around the string
✗ Incorrect
The puts method prints the string and adds a newline at the end.
2fill in blank
mediumComplete the code to print a string without a newline using print.
Ruby
print [1] Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Using puts which adds a newline
Using p which shows quotes
✗ Incorrect
The print method prints the string exactly as is, without adding a newline.
3fill in blank
hardFix the error in the code to show the string with quotes and newline using p.
Ruby
[1] "Hello, world!"
Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Using puts or print which do not show quotes
Using undefined method echo
✗ Incorrect
The p method prints the string with quotes and adds a newline.
4fill in blank
hardFill both blanks to print a string with and without newline.
Ruby
print [1] puts [2]
Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Using p in print line
Using print in puts line
✗ Incorrect
The first line prints "Hello" without newline, the second prints "World" with newline.
5fill in blank
hardFill all three blanks to print a string with quotes, without newline, and with newline.
Ruby
[1] "Test" print [2] puts [3]
Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Mixing up print and puts
Not using quotes for strings
✗ Incorrect
First line uses p to show quotes and newline, second prints without newline, third prints with newline.