Bird
0
0

What will this Ruby code print?

medium📝 Predict Output Q5 of 15
Ruby - Operators and Expressions
What will this Ruby code print?
score = 85
message = score >= 90 ? "Excellent" : score >= 75 ? "Good" : "Needs Improvement"
puts message
AExcellent
BNeeds Improvement
CGood
DSyntax Error
Step-by-Step Solution
Solution:
  1. Step 1: Evaluate the first condition score >= 90

    score is 85, which is less than 90, so this condition is false.
  2. Step 2: Evaluate the nested ternary score >= 75

    85 is greater than or equal to 75, so this condition is true, returning "Good".
  3. Final Answer:

    Good -> Option C
  4. Quick Check:

    Nested ternary picks "Good" for 85 score [OK]
Quick Trick: Nested ternary reads left to right carefully [OK]
Common Mistakes:
  • Choosing first false branch
  • Ignoring nested ternary
  • Assuming syntax error

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More Ruby Quizzes