Bird
0
0

Identify the problem in this code snippet:

medium📝 Debug Q7 of 15
Ruby - Control Flow
Identify the problem in this code snippet:
unless user.nil?
  puts 'No user'
end
ASyntax error due to missing end
BLogic is reversed; should use if instead of unless
CNo problem; code is correct
DShould use user == nil instead of user.nil?
Step-by-Step Solution
Solution:
  1. Step 1: Understand condition meaning

    user.nil? is true if user is nil.
  2. Step 2: Analyze unless logic

    unless user.nil? runs code if user is NOT nil, but message says 'No user', which is opposite.
  3. Final Answer:

    Logic is reversed; should use if instead of unless -> Option B
  4. Quick Check:

    unless negates condition; check message meaning [OK]
Quick Trick: Match message meaning with condition logic [OK]
Common Mistakes:
MISTAKES
  • Confusing nil? meaning
  • Using unless with opposite message
  • Ignoring logic inversion

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More Ruby Quizzes