Tell us what’s happening:
every time i write this code my browser crashes. and all the solutions are wrong… Here is the challenge:
The first type of loop we will learn is called a while
loop because it runs “while” a specified condition is true and stops once that condition is no longer true.
var ourArray = ;
var i = 0;
while(i < 5) {
ourArray.push(i);
i++;
}
``
In the code example above, the while
loop will execute 5 times and append the numbers 0 through 4 to ourArray
.
Let’s try getting a while loop to work by pushing values to an array.
Add the numbers 5 through 0 (inclusive) in descending order to myArray
using a while
loop.
All the solutions have an answer going [0,1,2,3,4,] <----thats “ascending” right?
descending would be [5, 4, 3, 2, 1, 0]
Your code so far
var myArray = [];
var i = 5;
while ( 0 < i < = 5) {
myArray. push(i);
i++;
```js
// Setup
var myArray = [];
// Only change code below this line.
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:
https://www.freecodecamp.org/learn/javascript-algorithms-and-data-structures/basic-javascript/iterate-with-javascript-while-loops