Bird
0
0

Identify the error in this Ruby code using a ternary operator:

medium📝 Debug Q6 of 15
Ruby - Operators and Expressions
Identify the error in this Ruby code using a ternary operator:
points = 50
status = points > 40 ? "Winner" "Loser"
puts status
AUsing double quotes instead of single quotes
BMissing colon ':' between true and false values
CIncorrect variable name 'points'
DNo error, code is correct
Step-by-Step Solution
Solution:
  1. Step 1: Review ternary syntax

    The ternary operator requires a colon ':' separating the true and false expressions.
  2. Step 2: Check the code

    The code has "Winner" "Loser" without a colon between them.
  3. Final Answer:

    Missing colon ':' between true and false values -> Option B
  4. Quick Check:

    Look for '?' and ':' in ternary [OK]
Quick Trick: Ternary needs '?' then ':' separating values [OK]
Common Mistakes:
MISTAKES
  • Omitting the colon ':'
  • Confusing quotes with syntax
  • Assuming variable name causes error

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More Ruby Quizzes