Practice - 5 Tasks
Answer the questions below
1fill in blank
easyComplete the code to print 'Hello' only if the condition is true using inline if.
Ruby
puts 'Hello' [1] condition
Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Using 'unless' instead of 'if' will run the code when the condition is false.
Using 'while' or 'until' here is incorrect because they are for loops.
✗ Incorrect
The inline if modifier is used as 'puts "Hello" if condition' to execute the code only when condition is true.
2fill in blank
mediumComplete the code to skip printing 'Goodbye' if the condition is true using inline unless.
Ruby
puts 'Goodbye' [1] condition
Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Using 'if' will run the code when the condition is true, which is the opposite of what is needed.
Using 'while' or 'until' is incorrect here because they are for loops.
✗ Incorrect
The inline unless modifier runs the code only if the condition is false, so 'puts "Goodbye" unless condition' skips printing when condition is true.
3fill in blank
hardFix the error in the code to print 'Done' only if the variable 'finished' is true using inline if.
Ruby
puts 'Done' [1] finished == true
Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Using 'unless' will run the code when 'finished == true' is false, which is incorrect here.
Using 'while' or 'until' causes syntax errors in this context.
✗ Incorrect
Using 'if' after the statement runs it only when 'finished == true' is true, which is the correct inline if usage.
4fill in blank
hardFill both blanks to print 'Alert!' only if 'warning' is true and skip if 'safe' is true using inline modifiers.
Ruby
puts 'Alert!' [1] warning [2] safe
Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Using 'unless' with 'warning' will invert the logic incorrectly.
Using 'if' with 'safe' will run code when safe is true, which is opposite of skipping.
✗ Incorrect
The code prints 'Alert!' if 'warning' is true and skips printing if 'safe' is true, so 'if' goes with 'warning' and 'unless' with 'safe'.
5fill in blank
hardFill all three blanks to print 'Success' only if 'passed' is true, skip if 'failed' is true, and repeat while 'retry' is true using inline modifiers.
Ruby
puts 'Success' [1] passed [2] failed [3] retry
Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Mixing 'if' and 'unless' incorrectly changes logic.
Using 'until' instead of 'while' changes loop condition.
✗ Incorrect
The code prints 'Success' if 'passed' is true (if), skips if 'failed' is true (unless), and repeats while 'retry' is true (while).