Bird
0
0

Which of the following is the correct syntax for a ternary operator in Ruby?

easy📝 Syntax Q12 of 15
Ruby - Control Flow
Which of the following is the correct syntax for a ternary operator in Ruby?
Acondition ? value_if_true : value_if_false
Bcondition : value_if_true ? value_if_false
Ccondition ? value_if_true ; value_if_false
Dcondition ? value_if_true, value_if_false
Step-by-Step Solution
Solution:
  1. Step 1: Recall ternary operator syntax

    The correct syntax places a question mark after the condition, then the true value, a colon, then the false value.
  2. Step 2: Compare options

    Only condition ? value_if_true : value_if_false matches the correct format: condition ? true_value : false_value.
  3. Final Answer:

    condition ? value_if_true : value_if_false -> Option A
  4. Quick Check:

    Syntax = condition ? true : false [OK]
Quick Trick: Remember: question mark before true, colon before false [OK]
Common Mistakes:
MISTAKES
  • Swapping question mark and colon
  • Using semicolon instead of colon
  • Separating values with comma

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More Ruby Quizzes