+ 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)
2 Respostas
+ 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.
+ 1
go thru the steps:
x=1
x=1 //multiply x by x
=3 //add 2
=9 // multiply x by x
=11 // add 2