Ruby - Control Flow
Which of the following shows the correct way to write a case/when statement in Ruby that prints "Hello" when the variable greeting is "hi"?
Which of the following shows the correct way to write a case/when statement in Ruby that prints "Hello" when the variable greeting is "hi"?
case statement uses when clauses to match values directly, not conditions.when 'hi' to match the value of greeting. case greeting
if 'hi'
puts 'Hello'
else
puts 'Goodbye'
end incorrectly uses if inside case. switch greeting
when 'hi'
puts 'Hello'
else
puts 'Goodbye'
end uses switch, which is not Ruby syntax. case greeting
when greeting == 'hi'
puts 'Hello'
else
puts 'Goodbye'
end incorrectly uses a condition inside when.case/when syntax matches values directly [OK]15+ quiz questions · All difficulty levels · Free
Free Signup - Practice All Questions