Bird
0
0

Identify the issue in this Ruby code snippet:

medium📝 Debug Q6 of 15
Ruby - Basics and Runtime
Identify the issue in this Ruby code snippet:
def multiply(x, y)
  x * y
end

puts multiply(4)
AThe method multiply should use 'return' explicitly
BThe method multiply is missing one argument when called
CThe method multiply should be defined with default parameters
DThe method multiply cannot multiply integers
Step-by-Step Solution
Solution:
  1. Step 1: Analyze method definition

    The method multiply expects two arguments: x and y.
  2. Step 2: Check method call

    Calling multiply(4) provides only one argument, causing an argument error.
  3. Step 3: Evaluate other options

    Explicit return is optional in Ruby (B). Default parameters (C) are not required but could fix the error. The method multiply cannot multiply integers is incorrect.
  4. Final Answer:

    The method multiply is missing one argument when called -> Option B
  5. Quick Check:

    Method arguments must match definition [OK]
Quick Trick: Check method call arguments match definition [OK]
Common Mistakes:
  • Thinking explicit return is required
  • Assuming Ruby methods can't multiply integers
  • Ignoring missing arguments in method calls

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More Ruby Quizzes