Bird
0
0

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

medium📝 Debug Q14 of 15
Ruby - Operators and Expressions
Find the error in this Ruby code using a ternary operator:
score = 75
result = score > 60 ? "Pass" "Fail"
puts result
AWrong variable name
BMissing colon between true and false values
CMissing question mark after condition
DUsing double quotes incorrectly
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 : false [OK]
Quick Trick: Always put ':' between true and false parts [OK]
Common Mistakes:
MISTAKES
  • Omitting the colon
  • Using comma instead of colon
  • Forgetting the question mark

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More Ruby Quizzes