var ourArray = [];
for (var i = 10; i > 0; i -= 2) {
ourArray.push(i);
}
// Setup
var myArray = [];
// Only change code below this line.
for (var i = 9; i > 0; i -= 2) {
myArray.push(i);
}
Since it’s a wiki entry, you ought to be able to make that change yourself. Give it a try. Click on the faded ellipses at the bottom, which should expand a toolbar. Then, click on the pencil icon to edit the post.
Something I’m not quite understanding with this one.
For the condition part in the middle of the for loop >= works, but > does not.
My understanding was that the condition is checked, and if returned True, then the final-expression is applied.
If that’s the case, shouldn’t (var i = 9; i > 1; i -= 2) work?
i.e. the final check before the condition becomes False would be on the number 3, which is greater than 1, so then 2 would be subtracted from 3. This leaves us with 1, which is not greater than 1, and the loop would end.
Using >= would surely cause the final-statement to be applied one more time to i as 1, leaving us with -1, no?
For comparison, the code that doesn’t pass:
// Setup
var myArray = [];
// Only change code below this line.
for (var i = 9; i > 1; i -= 2) {
myArray.push(i);
}
The code that does pass:
// Setup
var myArray = [];
// Only change code below this line.
for (var i = 9; i >= 1; i -= 2) {
myArray.push(i);
}