Bird
0
0

Find the error in this Ruby code:

medium📝 Debug Q6 of 15
Ruby - Operators and Expressions
Find the error in this Ruby code:
if true && !false
  puts "Yes"
else
  puts "No"
end
AIncorrect use of && operator
BNo error, code runs correctly
CMissing parentheses around !false
DMissing end keyword
Step-by-Step Solution
Solution:
  1. Step 1: Check syntax of logical operators

    The expression true && !false is valid Ruby syntax.
  2. Step 2: Verify code structure

    The if statement has matching end and correct indentation.
  3. Final Answer:

    There is no error; the code runs correctly -> Option B
  4. Quick Check:

    Logical operators used correctly, no syntax error [OK]
Quick Trick: Logical operators don't need extra parentheses unless for clarity [OK]
Common Mistakes:
  • Adding unnecessary parentheses
  • Thinking && is invalid here
  • Forgetting end keyword

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More Ruby Quizzes