+ 1

Solved

Can somebody explain why output is 11 I’m new to js so I don’t understand I feel stupid now but I really need help :( var x=1; for(;x<6;x+=2){ x=x*x } alert(x)

20th Aug 2018, 1:38 PM
Slavisa
Slavisa - avatar
2 Answers
+ 3
2 is added at the end of each iteration, therefore: 1. iteration: x = 1 * 1 => 1 x += 2 => 3 2. iteration (x is still smaller than 6): x = 3 * 3 => 9 x += 2 => 11 Now x doesn't satisfy the condition any longer, and the result is 11.
20th Aug 2018, 1:48 PM
Shadow
Shadow - avatar
+ 1
go thru the steps: x=1 x=1 //multiply x by x =3 //add 2 =9 // multiply x by x =11 // add 2
20th Aug 2018, 1:49 PM
J.G.
J.G. - avatar