+ 5

# What is the output of this code?

x = 8 x /= 2 y = 1 x.times {y+=2} puts y

8 Antworten

+ 23

9

+ 2

I figure it out.
thanks

+ 2

🔴Final Answer 3/3🔵 but first read process
x=8
x/=2
y=1
x.times{y+=2}
puts y
...................................
I understand this:
x=4
4.times{1+2}
puts y
Correct Output Answer
9

+ 2

i think ans is 9

+ 1

First the variable x is divided by 2, giving us a result of 2, then we put to variable y with 1.
Finally we make a loop with 4 iterations, (4*2) + 1 from y = 9

+ 1

9

0

Hi.
X =8
X=4
Y=1
4 times 1+=2
4*2+1=9
Final result is 9

0

I am sorry but i don’t understand why the output is 9. To me it would be 12.
I get all the variable right but why do we 4 times 1+=2 to 4*2+1? 🤷♂️