Bird
0
0

Which of the following is the correct way to write a ternary operator in Ruby?

easy📝 Syntax Q3 of 15
Ruby - Operators and Expressions
Which of the following is the correct way to write a ternary operator in Ruby?
Acondition ? true_value : false_value
Bcondition ? true_value, false_value
Ccondition : true_value ? false_value
Dcondition ? (true_value, false_value)
Step-by-Step Solution
Solution:
  1. Step 1: Recall ternary syntax

    The ternary operator syntax is: condition ? value_if_true : value_if_false
  2. Step 2: Match the options

    Only condition ? true_value : false_value matches this syntax exactly.
  3. Final Answer:

    condition ? true_value : false_value -> Option A
  4. Quick Check:

    Check for '?' followed by ':' [OK]
Quick Trick: Ternary uses '?' then ':' to separate values [OK]
Common Mistakes:
  • Using commas instead of colon
  • Swapping '?' and ':' positions
  • Adding parentheses incorrectly

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More Ruby Quizzes