+ 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

9th Jan 2021, 5:34 PM
DonSky
DonSky - avatar
3 RĂ©ponses
+ 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
9th Jan 2021, 5:38 PM
noteve
noteve - avatar
+ 3
《 Nicko12 》 Thanks alot. I replaced 3 with 4 and I got 12
9th Jan 2021, 5:45 PM
DonSky
DonSky - avatar