Tell us what’s happening:
Hi,
I passed the challenge but I am looking for some explanation to understand the code better.
What really confused me was the odd numbers. My first attempt was to do an i+= 3 but that narrowed it too much. Then I tried 2 and it worked but I don’t know why. Please could someone explain to me what is going on and why it works.
Your code so far
// Example
var ourArray = [];
for (var i = 0; i < 10; i += 2) {
ourArray.push(i);
}
// Setup
var myArray = [];
// Only change code below this line.
for (var i = 1; i <= 9; i += 2) {
myArray.push(i);
}
Your browser information:
Your Browser User Agent is: Mozilla/5.0 (Macintosh; Intel Mac OS X 10_13_3) AppleWebKit/604.5.6 (KHTML, like Gecko) Version/11.0.3 Safari/604.5.6
.
Link to the challenge:
https://www.freecodecamp.org/challenges/iterate-odd-numbers-with-a-for-loop