Bird
0
0

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

medium📝 Debug Q14 of 15
Ruby - Control Flow
Identify the error in this Ruby code using a ternary operator:
score = 85
result = score > 60 ? "Pass" "Fail"
puts result
AMissing question mark after condition
BMissing colon between true and false values
CTernary operator cannot be used with strings
DWrong variable name 'score'
Step-by-Step Solution
Solution:
  1. Step 1: Check ternary operator syntax

    The ternary operator requires a colon between the true and false values.
  2. Step 2: Identify missing colon

    The code has "Pass" "Fail" without a colon, causing a syntax error.
  3. Final Answer:

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

    Syntax = condition ? true_value : false_value [OK]
Quick Trick: Always put colon between true and false parts [OK]
Common Mistakes:
  • Omitting colon
  • Using comma instead of colon
  • Forgetting question mark

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More Ruby Quizzes