Bird
0
0

What will be the output of this Ruby code?

medium📝 Predict Output Q4 of 15
Ruby - Control Flow

What will be the output of this Ruby code?

temperature = 68
case temperature
in 80..100 then puts 'Hot'
in 60..79 then puts 'Warm'
in 40..59 then puts 'Cool'
else puts 'Cold'
end
ACold
BHot
CCool
DWarm
Step-by-Step Solution
Solution:
  1. Step 1: Identify the value

    The variable temperature is 68.
  2. Step 2: Check ranges in order

    68 falls within 60..79, so the 'Warm' branch executes.
  3. Final Answer:

    Warm -> Option D
  4. Quick Check:

    68 ∈ 60..79 [OK]
Quick Trick: Check which range includes the value first [OK]
Common Mistakes:
  • Choosing 'Hot' because 68 is close to 80
  • Ignoring the order of range checks
  • Assuming else runs when a range matches

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More Ruby Quizzes