Bird
0
0

What will this Ruby code print?

medium📝 Predict Output Q5 of 15
Ruby - Control Flow

What will this Ruby code print?

score = 85
if score >= 90
  puts "A"
elsif score >= 80
  puts "B"
else
  puts "C"
end
AA
BNo output
CC
DB
Step-by-Step Solution
Solution:
  1. Step 1: Check if score >= 90

    85 >= 90 is false, skip first block.
  2. Step 2: Check elsif score >= 80

    85 >= 80 is true, so print "B".
  3. Final Answer:

    B -> Option D
  4. Quick Check:

    First true condition runs, here elsif = B [OK]
Quick Trick: Check conditions top-down; first true block runs [OK]
Common Mistakes:
  • Choosing A incorrectly
  • Ignoring elsif block
  • Assuming else runs always

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More Ruby Quizzes