Ok, I’ve actually passed this exercise but I’ve come back to it because I don’t feel I fully understand what is happening.
In the for loop the first statement where we set “var i = 10”, wont this reset i to = 10 on each pass.
Why are we ending up with " ourArray = [10,8,6,4,2] " instead of just giving me an array full of 8’s, because we set i to = 10 and then it subtracts 2 each pass?
Your code so far
// Example
var ourArray = [];
for (var i = 10; i > 0; i -= 2) {
ourArray.push(i);
}
// Setup
var myArray = [];
for (var i = 9; i > 0; i -= 2) {
myArray.push(i);
}
// Only change code below this line.
Your browser information:
Your Browser User Agent is: Mozilla/5.0 (Macintosh; Intel Mac OS X 10_12_6) AppleWebKit/604.4.7 (KHTML, like Gecko) Version/11.0.2 Safari/604.4.7
.
Link to the challenge:
https://www.freecodecamp.org/challenges/count-backwards-with-a-for-loop