Iterate With JavaScript While Loops not working

This challenge keeps on telling me something has snapped. It happens every time I try to complete the code in the editor. All the other challenges have worked fine, I skipped ahead one challenge and those work fine also. Just letting you guys know. Apart from that, really enjoying this course & leaning loads.

My guess is you created an infinite loop. Would you mind posting the code you were trying?

// Setup
var myArray = ;

// Only change code below this line.
var i = 0;
while(i < 6) {
myArray.push(i);

i--;

}
console.log(myArray)

Hi @Xennett101,
You created a infinite loop in your code:

  • you declared i with the value of 0
  • you push i to myArray and minus it by 1 while i is less than 6
    so the value of i goes 0 -> -1 -> -2 -> … and it’s all less than 6 thus an infinite loop is created.

Hope this helps!

Yes, I see. Always less than 6 so it never ends. Thank you very much, I’ll go back and reset the code.

type it into vscode or something and copy paste your solution all at once to fcc because its running before you can tell it what to do. also try using i++ before you list the push to maybe prevent this if you dont wish to use a code editor.

Yes, thanks. I’m working on it now after resetting, then going back into it. Thing is it snapped again, so I’ll try that suggestion…

Copy and paste like this. Or try first on fcc, place i++ before for push line.