You should be using a for loop for this

You should be using a for loop for this
0

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.

@adamszczechura It turns out a bug was introduced for a few challenges when a pull request was merged yesterday. I am working on fixing the bug right now and hope to have the issue fixed as soon as possible.

3 Likes

Solved copying what Jacob wrote ty

1 Like

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

We moved the example code out of the editor. The challenge test is looking to see two for loops, but because the example code for loop was removed, the tests fails since the solution would only have a single for loop in it. I am rewriting the tests to not look at the number of for loops, because that was a very brittle test to begin with.

2 Likes

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); 
} 

Because you have a comment which has for () in it. That is a separate bug issue that we are going to address at a later time.

3 Likes

@Sky020 @lasjorg If you have a chance, please review this PR.

1 Like