Bird
0
0

Find the error in this Ruby code snippet:

medium📝 Debug Q6 of 15
Ruby - Control Flow
Find the error in this Ruby code snippet:
value = 15
case value
in 10-20 then puts 'In range'
else puts 'Out of range'
end
ARange syntax is incorrect; should use two dots (..)
BMissing <code>then</code> keyword
CVariable <code>value</code> is not defined
DNo error; code runs fine
Step-by-Step Solution
Solution:
  1. Step 1: Check the range syntax

    The code uses 10-20 which is subtraction, not a range.
  2. Step 2: Correct range syntax in Ruby

    Ranges use two dots .. for inclusive ranges, so it should be 10..20.
  3. Final Answer:

    Range syntax is incorrect; should use two dots (..) -> Option A
  4. Quick Check:

    Ranges need two dots, not dash [OK]
Quick Trick: Use two dots for ranges, not dash [OK]
Common Mistakes:
  • Using dash instead of two dots
  • Ignoring syntax errors
  • Confusing subtraction with range

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More Ruby Quizzes