Tell us what’s happening:
- My code doesn’t give correct output.
- in the previous exercise (while loop), variable i was declared outside the loop, but this step was skipped in for loop exercise. Isn’t it necessary to declare variables outside the loop?
Your code so far
// Example
var ourArray = [];
for (var i = 0; i < 5; i++) {
ourArray.push(i);
}
// Setup
var myArray = [];
// Only change code below this line.
for (var j = 1; j < 5; j++) {
myArray.push(j);
}
Your browser information:
User Agent is: Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/69.0.3497.100 Safari/537.36.
Link to the challenge:
https://learn.freecodecamp.org/javascript-algorithms-and-data-structures/basic-javascript/iterate-with-javascript-for-loops