Bird
0
0

Find the error in this Ruby code snippet:

medium📝 Debug Q7 of 15
Ruby - Enumerable and Collection Processing
Find the error in this Ruby code snippet:
array = [10, 20, 30]
array.each { |num| puts num * 2
}
ANo error, code runs fine
BIncorrect multiplication operator
CMissing closing brace for block
DBlock variable not defined
Step-by-Step Solution
Solution:
  1. Step 1: Check block syntax

    The block starts with { and ends with }, and the block variable is correctly defined.
  2. Step 2: Verify code correctness

    The multiplication operator is correct, and the block is properly closed.
  3. Final Answer:

    No error, code runs fine -> Option A
  4. Quick Check:

    Proper block syntax means no error [OK]
Quick Trick: Braces {} must open and close the block properly [OK]
Common Mistakes:
  • Thinking missing brace due to newline
  • Confusing operators
  • Misreading block variable

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More Ruby Quizzes