+ 2
Can someone tell me why the answer is 9
arr = [2, 4, 6] sum = 0 arr.each do |x| sum += 3 end puts sum #output=9
3 Answers
+ 4
because it says
"sum += 3" and not "sum += x"
So every iteration, the sum is added by 3, and arr has 3 elements so it means 3 iterations.
sum = 0
LOOP
*- - - start - - - *
sum = 3
sum = 6
sum = 9
*- - - end - - - *
puts sum
>> 9
+ 3
ă Nicko12 ă Thanks alot.
I replaced 3 with 4 and I got 12
+ 2