Bird
0
0

Find the problem in this Ruby ternary expression:

medium📝 Debug Q7 of 15
Ruby - Operators and Expressions
Find the problem in this Ruby ternary expression:
value = 10
result = value > 5 ? "High" :
"Low"
puts result
ASyntax error due to line break without parentheses
BNo error, code works correctly
CMissing question mark '?'
DIncorrect variable assignment
Step-by-Step Solution
Solution:
  1. Step 1: Check if line break affects ternary syntax

    Ruby allows line breaks after the colon ':' without parentheses if indentation is correct.
  2. Step 2: Confirm code runs without error

    The code assigns "High" because 10 > 5 is true, so result is "High" and prints it correctly.
  3. Final Answer:

    No error, code works correctly -> Option B
  4. Quick Check:

    Line breaks allowed after ':' if syntax is clear [OK]
Quick Trick: Line breaks okay if syntax is clear [OK]
Common Mistakes:
MISTAKES
  • Assuming line break causes error
  • Missing '?' in ternary
  • Wrong variable usage

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More Ruby Quizzes