Recall & Review
beginner
What is the purpose of an
if statement in Ruby?An
if statement lets the program choose to run some code only when a condition is true.Click to reveal answer
beginner
How do you write an
elsif in Ruby?Use
elsif to check another condition if the first if condition is false. It comes after if and before else.Click to reveal answer
beginner
What does the
else part do in an if statement?else runs code when all previous if and elsif conditions are false.Click to reveal answer
intermediate
Write a simple Ruby
if-elsif-else statement that prints 'Cold', 'Warm', or 'Hot' based on a temperature variable.Example:
temp = 30 if temp < 10 puts 'Cold' elsif temp < 25 puts 'Warm' else puts 'Hot' end
Click to reveal answer
intermediate
Can you have multiple
elsif branches in one if statement?Yes, you can have many
elsif branches to check several conditions in order.Click to reveal answer
What will this Ruby code print?<br>
if false puts 'Yes' else puts 'No' end
✗ Incorrect
Since the condition is false, the
else block runs and prints 'No'.Which keyword checks a second condition if the first
if is false?✗ Incorrect
elsif lets you check another condition after if.What happens if none of the
if or elsif conditions are true and there is no else?✗ Incorrect
If no conditions match and no
else exists, no code inside the statement runs.How do you end an
if statement in Ruby?✗ Incorrect
Ruby uses
end to close if statements.Which is the correct order in Ruby conditional statements?
✗ Incorrect
The order is
if, then zero or more elsif, then optional else.Explain how
if, elsif, and else work together in Ruby.Think of it like choosing one path out of many based on conditions.
You got /3 concepts.
Write a Ruby example using
if, elsif, and else to decide what to wear based on temperature.Use temperature ranges to decide clothes.
You got /4 concepts.