Bird
0
0

What will this Ruby code output?

medium📝 Predict Output Q5 of 15
Ruby - Methods
What will this Ruby code output?
def multiply(x, y)
  x * y
end

puts multiply(5, 3)
A8
BError: wrong number of arguments
C53
D15
Step-by-Step Solution
Solution:
  1. Step 1: Understand method parameters and operation

    The method multiply takes two arguments and returns their product.
  2. Step 2: Calculate the result of multiply(5, 3)

    5 multiplied by 3 equals 15, which is printed.
  3. Final Answer:

    15 -> Option D
  4. Quick Check:

    Multiplying arguments returns product [OK]
Quick Trick: Multiply parameters inside method to get product [OK]
Common Mistakes:
MISTAKES
  • Adding instead of multiplying
  • Concatenating numbers as strings
  • Passing wrong number of arguments

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More Ruby Quizzes