Bird
0
0

What is the output of this Ruby code?

medium📝 Predict Output Q13 of 15
Ruby - Operators and Expressions
What is the output of this Ruby code?
age = 20
message = age >= 18 ? "Adult" : "Minor"
puts message
AMinor
B20
CSyntaxError
DAdult
Step-by-Step Solution
Solution:
  1. Step 1: Evaluate the condition age >= 18

    Since age is 20, which is greater than or equal to 18, the condition is true.
  2. Step 2: Apply the ternary operator

    Because the condition is true, message is assigned "Adult".
  3. Final Answer:

    Adult -> Option D
  4. Quick Check:

    20 >= 18 ? "Adult" : "Minor" = "Adult" [OK]
Quick Trick: Check condition result first, then pick true or false value [OK]
Common Mistakes:
MISTAKES
  • Choosing the false value by mistake
  • Printing the variable instead of its value
  • Confusing syntax errors

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More Ruby Quizzes