Bird
0
0

What is the output of this Ruby code?

medium📝 Predict Output Q13 of 15
Ruby - Functional Patterns in Ruby
What is the output of this Ruby code?
def multiply(x, y)
  x * y
end

result = multiply(3, 4)
puts result
AError
Bnil
C12
D7
Step-by-Step Solution
Solution:
  1. Step 1: Understand the multiply function

    The function returns the product of x and y, so multiply(3, 4) returns 12.
  2. Step 2: Check the output statement

    puts prints the returned value, so it prints 12.
  3. Final Answer:

    12 -> Option C
  4. Quick Check:

    multiply(3,4) = 12 [OK]
Quick Trick: Pure functions return predictable output; multiply(3,4) = 12 [OK]
Common Mistakes:
  • Thinking function returns nil if no explicit return
  • Confusing addition with multiplication
  • Expecting error due to missing return keyword

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More Ruby Quizzes