Iterate with Javascript While Loops crashing Chrome

Iterate with Javascript While Loops crashing Chrome
0

Tell us what’s happening:

Chrome browser is crashing (aw snap) when trying to run the test, and then crashes every time the page is reloaded.

Your code so far

// Setup
var myArray = [];

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

Your browser information:

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

Challenge: Iterate with Javascript While Loops

Link to the challenge:

Hello CTHobbit.

You have written an infinite loop. This means your block of code:

while (i >= 0) {
  myArray.push(i);
  i++;
}

Will never stop running, because i is always greater than > or equal to = 0.

To solve, reset the code.

Hope this helps.

Woops! I incremented instead of decremented. Thanks!

1 Like