Bird
0
0

Identify the problem in this Ruby code:

medium📝 Debug Q7 of 15
Ruby - Control Flow

Identify the problem in this Ruby code:

if score > 50
  puts "Pass"
elsif score < 50
  puts "Fail"
else
  puts "Invalid"
end

Assuming score is 50.

AThe else block runs when score is 50
BThe elsif condition should be >= 50
CThe else block will never run
DThe code will cause a syntax error
Step-by-Step Solution
Solution:
  1. Step 1: Evaluate conditions with score = 50

    score > 50 is false, score < 50 is false.
  2. Step 2: Determine which block runs

    Since both conditions are false, else block runs and prints "Invalid".
  3. Final Answer:

    The else block runs when score is 50 -> Option A
  4. Quick Check:

    Else runs if no prior condition matches = C [OK]
Quick Trick: Else runs when all conditions are false [OK]
Common Mistakes:
MISTAKES
  • Assuming else never runs
  • Confusing condition boundaries
  • Thinking elsif covers all cases

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More Ruby Quizzes