+ 3
I'm pretty sure this causes an error, since you left out 2 in the conditional part of the for loop, and you defined count instead of loop. But here's how it works: loop and x both start off as 0. Loop gets incremented, then loop - x is displayed on the screen. 1 - 0 equals 1. Them, both x and loop gets incremented, and 2 - 1 (1) gets printed on the screen again, then again one last time: 3 - 2 (still 1) (fixed code:) var loop = 0; for (var x = 0; x <= 2; x++) { ++loop; document.write(loop - x); }
1st Jul 2019, 9:15 AM
Airree
Airree - avatar