Bird
0
0

What will the following Ruby code return?

easy📝 Conceptual Q1 of 15
Ruby - Control Flow
What will the following Ruby code return?
result = 5 > 3 ? "Yes" : "No"
A"No"
Bfalse
Ctrue
D"Yes"
Step-by-Step Solution
Solution:
  1. Step 1: Evaluate the condition 5 > 3

    The condition 5 > 3 is true because 5 is greater than 3.
  2. Step 2: Apply the ternary operator

    Since the condition is true, the expression returns the value before the colon, which is "Yes".
  3. Final Answer:

    "Yes" -> Option D
  4. Quick Check:

    Condition true returns first value [OK]
Quick Trick: If condition true, ternary returns first value before colon [OK]
Common Mistakes:
  • Confusing true and false branches
  • Misreading the condition
  • Using quotes incorrectly

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More Ruby Quizzes