// Setup
var myArray = [];
// Only change code below this line
for(var i = 1; i < 10; i += 2) {
myArray.push(i)
}
console.log(myArray)
The lesson showed an example of a “for” loop:
var ourArray = [];
for (var i = 0; i < 10; i += 2) {
ourArray.push(i);
}
But when I replicate the exact same code it and console.log it, it shows [ 0, 2, 4, 6, 8 ].
My question is: shouldn’t 8 pass through the condition then become 10 since 8 is less than 10?
Your browser information:
User Agent is: Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/81.0.4044.138 Safari/537.36.
When i == 8, the exit condition has not been met, so the loop body executes and then the iterator increments to i == 10, which causes the exit condition to trigger.