Bird
0
0

What is the output of this Ruby code?

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

    The condition age >= 18 is true because age is 20.
  2. Step 2: Apply ternary operator

    Since the condition is true, the expression returns "Adult".
  3. Final Answer:

    Adult -> Option D
  4. Quick Check:

    20 >= 18 ? "Adult" : "Minor" = "Adult" [OK]
Quick Trick: Check condition true? pick first value, else second [OK]
Common Mistakes:
  • Choosing the false value by mistake
  • Printing the variable instead of result
  • Expecting syntax error

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More Ruby Quizzes