Bird
0
0

What will be the output of this Ruby code?

medium📝 Predict Output Q4 of 15
Ruby - Control Flow
What will be the output of this Ruby code?
score = 75
unless score >= 80
  puts 'Below target'
else
  puts 'Target met'
end
ABelow target
BTarget met
CNo output
DSyntax error
Step-by-Step Solution
Solution:
  1. Step 1: Evaluate the condition

    Condition is score >= 80. Since score is 75, condition is false.
  2. Step 2: Apply unless logic

    unless runs code when condition is false, so it runs puts 'Below target'.
  3. Final Answer:

    Below target -> Option A
  4. Quick Check:

    unless false runs code [OK]
Quick Trick: unless runs code when condition is false [OK]
Common Mistakes:
  • Thinking unless runs when true
  • Confusing else block output
  • Ignoring condition evaluation

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More Ruby Quizzes