Bird
0
0

Find the error in this Ruby code that aims to keep code simple and happy:

medium📝 Debug Q14 of 15
Ruby - Basics and Runtime
Find the error in this Ruby code that aims to keep code simple and happy:
def add(a, b)
  return a + b
end

puts add(5)
AMissing second argument when calling add
BUsing return keyword is not allowed in Ruby
CMethod name add is reserved
Dputs cannot print method results
Step-by-Step Solution
Solution:
  1. Step 1: Check method parameters and call

    The method add expects two arguments, but only one (5) is given.
  2. Step 2: Understand Ruby argument rules

    Calling add with fewer arguments causes an ArgumentError.
  3. Final Answer:

    Missing second argument when calling add -> Option A
  4. Quick Check:

    Argument count mismatch = error [OK]
Quick Trick: Count method arguments carefully [OK]
Common Mistakes:
MISTAKES
  • Thinking return is disallowed
  • Assuming method names are reserved
  • Believing puts can't print results

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More Ruby Quizzes