Bird
0
0

Find the error in this Ruby code snippet:

medium📝 Debug Q14 of 15
Ruby - Control Flow

Find the error in this Ruby code snippet:

number = 10
if number > 5
  puts "Big"
elsif number < 3
  puts "Small"
else
  puts "Medium"
AWrong keyword <code>elsif</code> should be <code>else if</code>.
BMissing <code>end</code> to close the <code>if</code> statement.
CThe <code>puts</code> statements need parentheses.
DThe comparison operators are incorrect.
Step-by-Step Solution
Solution:
  1. Step 1: Check Ruby syntax completeness

    Ruby if statements must end with end. The code snippet is missing end.
  2. Step 2: Verify other parts

    elsif is correct in Ruby. puts can be used without parentheses. Comparison operators are correct.
  3. Final Answer:

    Missing end to close the if statement. -> Option B
  4. Quick Check:

    Every if needs end [OK]
Quick Trick: Always close if with end [OK]
Common Mistakes:
  • Replacing elsif with else if
  • Adding unnecessary parentheses to puts
  • Changing correct comparison operators

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More Ruby Quizzes