Bird
0
0

Find the error in this Ruby code using unless:

medium📝 Debug Q6 of 15
Ruby - Control Flow
Find the error in this Ruby code using unless:
unless x > 10
  puts 'Small'
else
  puts 'Large'
AShould use if instead of unless
BIncorrect use of else with unless
CCondition should be negated explicitly
DMissing <code>end</code> to close the unless block
Step-by-Step Solution
Solution:
  1. Step 1: Check block structure

    Ruby requires end to close unless blocks.
  2. Step 2: Identify missing end

    The code lacks end after else block, causing syntax error.
  3. Final Answer:

    Missing end to close the unless block -> Option D
  4. Quick Check:

    All blocks need end in Ruby [OK]
Quick Trick: Always close unless blocks with end [OK]
Common Mistakes:
  • Forgetting end
  • Thinking else not allowed
  • Misusing condition negation

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More Ruby Quizzes