The code you provided has a syntax error. There are two issues with the code:
The method definition is missing parentheses after the method name. It should be def taker(n)
instead of def taker n
.
The sum
method does not exist for an array in Ruby. You can replace mul.sum
with mul.inject(:+)
to find the sum of elements in the array.
Here's the corrected code:
main.rb126 chars10 lines
This code will output the sum of all numbers from 1 to n
that are divisible by both 3 and 5.
gistlibby LogSnag