Bird
0
0

Identify the error in this Ruby code snippet:

medium📝 Debug Q6 of 15
Ruby - Control Flow

Identify the error in this Ruby code snippet:

case number
when 1
  puts 'One'
when 2
  puts 'Two'
else
  puts 'Other'
AMissing <code>end</code> to close the case statement
BIncorrect use of <code>else</code> keyword
CMissing parentheses in <code>when</code> clauses
DUsing puts inside case is invalid
Step-by-Step Solution
Solution:
  1. Step 1: Check syntax completeness

    The case statement is missing the closing end keyword.
  2. Step 2: Confirm other parts are correct

    else is used correctly, parentheses are optional, and puts is valid.
  3. Final Answer:

    Missing end to close the case statement -> Option A
  4. Quick Check:

    case must end with end [OK]
Quick Trick: Always close case with end keyword [OK]
Common Mistakes:
MISTAKES
  • Forgetting end keyword
  • Misusing else keyword
  • Thinking parentheses are required

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More Ruby Quizzes