+ 5
javascript conditionals and loops-module 3 quiz-first question
What is the output of this code? var x = 0; while(x<6) { x++; } document.write(x); If i am not wrong the answer should be 5 but it accepts 6 for correct which is not right, right? it would have been if x<=6...
7 odpowiedzi
+ 12
the answer is 6. Run it in the code playground to test.
The last time x is tested in the loop it has value 6.
6 < 6 --> false. That's what makes the loop stop.
+ 11
The condition 6<6 ends the loop, but the print statement is after the loop.
0
Hi, thank you for your reply. But if 6<6 is false, why would it print it anyway? After a little pondering, I wonder wheter the answer is 6 because last true number is 5 then we have x++ which makes it 6?
0
Ahh! Thank you again! I got it this time :))))
0
To loop over the value of x. Here from 0 to 5. Should print 0, 1, 2 3, 4 ,5 .
0
what is the second question?
0
6