Bird
0
0

What will be the output of this Ruby code?

medium📝 Predict Output Q13 of 15
Ruby - Control Flow
What will be the output of this Ruby code?
score = 85
case score
when 90..100
  puts 'Excellent'
when 75..89
  puts 'Good'
else
  puts 'Needs Improvement'
end
AExcellent
BNeeds Improvement
CGood
DNo output
Step-by-Step Solution
Solution:
  1. Step 1: Understand the case statement ranges

    The case checks if score is in 90 to 100, then 75 to 89, else other.
  2. Step 2: Check where 85 fits

    85 is between 75 and 89, so it matches the second when clause.
  3. Final Answer:

    Good -> Option C
  4. Quick Check:

    85 in 75..89 = Good [OK]
Quick Trick: Match value to range in case when clauses [OK]
Common Mistakes:
  • Choosing 'Excellent' for 85
  • Thinking else runs for 85
  • Confusing ranges with single values

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More Ruby Quizzes