Bird
0
0

Find the error in this Ruby code snippet:

medium📝 Debug Q14 of 15
Ruby - Operators and Expressions
Find the error in this Ruby code snippet:
if !true || false
  puts "Yes"
else
  puts "No"
end
ANo error; code runs and prints "No"
BThe ! operator cannot be used with true
CThe || operator should be && here
DMissing parentheses around !true
Step-by-Step Solution
Solution:
  1. Step 1: Check syntax of logical operators

    Using ! with true is valid and reverses it to false. The || operator is also valid here.
  2. Step 2: Evaluate the condition

    !true is false, so condition is false || false, which is false. The else branch runs printing "No".
  3. Step 3: Confirm no syntax errors

    The code syntax is correct and will run without errors.
  4. Final Answer:

    No error; code runs and prints "No" -> Option A
  5. Quick Check:

    Logical operators used correctly = B [OK]
Quick Trick: !true is valid; check logic, not syntax [OK]
Common Mistakes:
  • Thinking !true is invalid
  • Confusing || with &&
  • Expecting syntax error without parentheses

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More Ruby Quizzes