Bird
0
0

What is the output of this Ruby code?

medium📝 Predict Output Q4 of 15
Ruby - Control Flow

What is the output of this Ruby code?

score = 85
case score
when 90..100
  puts "Excellent"
when 80..89
  puts "Good"
when 70..79
  puts "Average"
else
  puts "Fail"
end
AExcellent
BGood
CAverage
DFail
Step-by-Step Solution
Solution:
  1. Step 1: Identify which range score falls into

    Score is 85, which fits in the range 80..89.
  2. Step 2: Match the when clause

    The when 80..89 clause matches, so it executes puts "Good".
  3. Final Answer:

    Good -> Option B
  4. Quick Check:

    Range matching in when = Good [OK]
Quick Trick: Ranges in when match values inside them [OK]
Common Mistakes:
  • Choosing wrong range
  • Ignoring else clause
  • Confusing output with other ranges

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More Ruby Quizzes