0
0
Rubyprogramming~10 mins

Inline if and unless (modifier form) 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 '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'
Aunless
Bif
Cwhile
Duntil
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.
2fill in blank
medium

Complete 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'
Awhile
Bif
Cunless
Duntil
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.
3fill in blank
hard

Fix 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'
Aunless
Bwhile
Cuntil
Dif
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.
4fill in blank
hard

Fill 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'
Aif
Bunless
Cwhile
Duntil
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.
5fill in blank
hard

Fill 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'
Aif
Bunless
Cwhile
Duntil
Attempts:
3 left
💡 Hint
Common Mistakes
Mixing 'if' and 'unless' incorrectly changes logic.
Using 'until' instead of 'while' changes loop condition.