I need help! in this

Tell us what’s happening:

Your code so far


// Setup
var myArray = [];

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

i need some help i do all combinations try many code even try the solution given but its not working and sometimes it show aw snap we could't load webpage

Your browser information:

User Agent is: Mozilla/5.0 (Windows NT 6.1) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/78.0.3904.108 Safari/537.36.

Challenge: Iterate with JavaScript While Loops

Link to the challenge:
https://www.freecodecamp.org/learn/javascript-algorithms-and-data-structures/basic-javascript/iterate-with-javascript-while-loops

The test that fails expects the result to be [5,4,3,2,1,0] and your variable has [0,1,2,3,4].

Reverse the while to go from 5 to 0

You need to set the value of i to be 5 i.e. var i=5; then add while condition while(i>=0) and decrease value of i i.e. i-- to pass the test.

In the Debugging section, you learned how to check the value of variables with console.log statements. Try adding console.log(myArray) after the while loop ends to see the value.

I can confirm this is also happening on my end as well. Also, when this happens, the forum also goes down as well.

@Madalena.design With the code posted above, you are getting this message?

@RandellDawson What is happening is when I opened up the link and start reading the information about this challenge, I get the sudden “aw snap” message popping up. I couldn’t even finish reading a paragraph.

I made that mistake too – I was making a perfectly good array… but not following the directions :wink:

Can you please take a screenshot showing the entire page (with code in editor and error message)?

I am using the browser Chrome.

I have tried it again and it did happen, but it didn’t happen immediately like before. For demonstration purpose: this is what is showing on my end:

When it happens, the forum also goes down with it.

I hope this helps.

@Madalena.design Anyway to grab a screenshot of what the code in the editor looks like before it goes to the screen above?

Well, the first couple of times, it was looking like this before:

But when I tried it again now, it was all good until I have copied and pasted @gautamdhingra’s code in and changed the ++ sign to --, then it happens (hope that made sense).

If you pasted @gautamdhingra’s code and changed i++ to i--, you created an infinite loop, which will crash the browser. Why? Because i would forever be less than or equal to 4.

Now, every time you load the page, it will try running the last code you had in it (the infinite loop). To fix this, you need to clear the cache.

1 Like

That would have explained it. I didn’t realise that when even writing the code in the editor, it is actually running the code (I thought to run it is to press ‘Run the Test’ button. My bad!

Before the changes to the curriculum back in June of 2018, it had this feature. From June 2018 until less than a week ago, the feature was not present. Now, we have the feature back again, so users can see the changes (errors and all) as they make changes to their code.

I see, that does make more sense now (especially I am not currently learning through FCC at this moment). Thank you for explaining this one as I do plan to use the curriculum to learn in near future.

I think it is safe to say when I get to Javascript stage, you will probably seeing more of my posts wailing for help haha. :slight_smile:

Again, thank you.

1 Like

bro i tried that too but whenever i try that a aw,snap page occurs

when ever i try i-- page crash but now its solved i try i-=1 thanks :slight_smile:

i-- and i-=1 can be the same. It really depends on what the rest of your code looks like. Please post the code you used with i-- that did not work and I will try to explain what the problem is.