Issue with the Iterate with JavaScript While Loops page

Hiya,

So when I am trying to complete this problem on freecodecamp, when I have what I beleive to be the correct answer, it seems to be brekaing chrome! or something the website crashes anyway…

I must have the code wrong… can someone be kind enough to check this out for me and see if it is only my end that is playing up?

Mind posting your code on here? That link just takes me to the exercise.

var myArray = [];

var i = 5;
while (i > 0) {
myArray.push(i);
i--;
}

@Wahzammo Your code only adds the number 5 through 1 (inclusive). You need to make a small adjustment to your while loop condition, so myArray also includes 0.

oh yeah cool, thanks for pointing that out…

Still breaks the webpage thou on my end!

What is your latest code attempt?

Thanks! So the code doesn’t seems to be valid as it doesn’t’ cause any infinite loops, however you are close to the correct answer. Try console logging what myArray gives you, and you should see where the mistake is coming from, I made one code change and got it to pass from your code.

Ok, so I’m close which is good…

But it looks like I’m having other issues with website itself as now when I type at all it crashes…
I was happening on my computer at work yesterday also… so I will run it in VS and play with it in there for a bit…

Sounds like you have created an infinite loop in your latest code attempt.

var myArray = [];

var i = 0;
while(i < 6) {
    myArray.unshift(i);
    i++;
}

SUCCESS!

All you had to do with your first code attempt is change the > to >= in the while loop condition.

I am a industrial sparky, we have counters n such in our PLC programs… I was just looking with those eyes, not prgrammer eyes hahaha

so simple once I saw it… :slight_smile:

I think the i-- stuff is screwing with chrome, for some reason??? i dunno but whenever I tried that way, the webpage shit itself.

I use Chrome and making the change I suggested above fixed your original code and passed all the tests.

well thats weird hahahaha

anyway I’ve learnt a lot from that one problem!

1 Like

They do that haha =) The best learning experiences seem at least in my experience to be the ones you learn the most from. Keep it up you got this! =)