You should be using a for loop for this

So the thing is fairly simple to do and my code does what is supposed to but I’m getting the massage that I should be using For Loop for this. But I am. I am blind to see what’s wrong with my code.

EDIT: I am also getting the same message in the next lesson which is pretty similar.

Your code so far


// Setup
var myArray = [];

// Only change code below this line
for (var a =1; a < 6; a++)  {
myArray.push(a);
}
console.log(myArray);

Your browser information:

User Agent is: Mozilla/5.0 (Windows NT 6.1; Win64; x64; rv:74.0) Gecko/20100101 Firefox/74.0.

Challenge: Iterate with JavaScript For Loops

Link to the challenge:

Thank you for helping make FCC better. Bugs can be reported as GitHub Issues. Whenever reporting a bug, please check first that there isn’t already an issue for it and provide as much detail as possible.

Where does the consol.log come from?
also doesn’t there need to be more space?

It could be whitespace is causing the tests to not handle it correctly.

1 Like

It worked, thanks. Weird 'cause there was a space there in the example.

1 Like

console.log is just for my convinence

1 Like

But in the next lesson it doesn’t work for some reason. My code is:

// Setup

var myArray = ;

// Only change code below this line

for(var i=1; i<10; i+=2) {

myArray.push(i);

}

So when I copy this and modify it to fit the lesson it works with every one. If I copy only bottom part it still doesn’t work. If I write exactly what you wrote it doesn’t work either.

Same problem here except it doesn’t work even when copying the one you wrote

You’re copying what I wrote or what Jacob wrote?

I can confirm. Its a bug. I’m sure they will fix it soon.

Solved copying what Jacob wrote ty

1 Like

Can you educate us on what exactly is causing the problem?

So why did it work with this code?

var myArray = []; 
// I closed the space between for () to for()
for(var i=1; i < 6; i++){ 
// using "i" is just a convention 
// not technically right or wrong
myArray.push(i); 
}