Bird
0
0

Find the error in this Ruby code snippet:

medium📝 Debug Q7 of 15
Ruby - Basics and Runtime
Find the error in this Ruby code snippet:
if true
  puts "Yes"
else
  puts "No"
AIncorrect use of quotes
BSyntax error in else keyword
CMissing 'end' keyword to close if statement
DNo error, prints 'Yes'
Step-by-Step Solution
Solution:
  1. Step 1: Check if statement syntax

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

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

    Missing 'end' keyword to close if statement -> Option C
  4. Quick Check:

    Every if needs 'end' [OK]
Quick Trick: Always close if with 'end' [OK]
Common Mistakes:
MISTAKES
  • Forgetting 'end' keyword
  • Misusing quotes
  • Thinking else causes syntax error

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More Ruby Quizzes