+ 2

Why is answer 11???

for(x=1; x<6; x+=2) { x=x*x} alert (x)

4th Sep 2017, 7:07 AM
Oleg Larskiy
Oleg Larskiy - avatar
2 Réponses
+ 13
for (x = 1; x < 6; x += 2) x = x * x alert(x) x is 1. x < 6 is true, first loop executes. x = 1 * 1, x is 1. x += 2, x is 3. x is 3. x < 6 is true, second loop executes. x = 3 * 3, x is 9. x += 2, x is 11. x is 11. x < 6 is false, loop ends. alert(x). Outputs 11.
4th Sep 2017, 7:14 AM
Hatsy Rei
Hatsy Rei - avatar
+ 1
holly js! thanks))))))
4th Sep 2017, 7:20 AM
Oleg Larskiy
Oleg Larskiy - avatar