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
result = score >= 90 ? "A" : score >= 80 ? "B" : "C"
puts result
AA
BB
CC
DSyntax Error
Step-by-Step Solution
Solution:
  1. Step 1: Evaluate first condition score >= 90

    score is 85, so 85 >= 90 is false.
  2. Step 2: Evaluate nested ternary score >= 80

    Since first condition is false, check second condition: 85 >= 80 is true, so result is "B".
  3. Final Answer:

    B -> Option B
  4. Quick Check:

    Nested ternary evaluates left to right [OK]
Quick Trick: Nested ternaries evaluate conditions in order, left to right [OK]
Common Mistakes:
  • Thinking nested ternary is syntax error
  • Ignoring second condition
  • Misreading comparison operators

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More Ruby Quizzes