While loop challenge

Tell us what’s happening:

Hi, just answered the while loop problem with this and it is not passing. Could anyone help?

// Setup
var myArray = ;

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


// Setup
var myArray = [];

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

Your browser information:

User Agent is: Mozilla/5.0 (Macintosh; Intel Mac OS X 10_13_6) AppleWebKit/605.1.15 (KHTML, like Gecko) Version/13.1.2 Safari/605.1.15.

Challenge: Iterate with JavaScript While Loops

Link to the challenge:

Hi there,
You should start your index with 5 var i = 5; and every time you do the while loop you should decrement the index intead of i++, so you can go from 5 to 4;

Let me us know :slight_smile:

Hi Ivan,

This is just what I am doing but it still not working… I had the same problem in the Use the Conditional Ternary Operator. Apparently there is no syntax errors but the machine does not process it…

Thank you anyway.

Stay safe.

So then ure code should look like the one above right?

However this

while(i<5){

tells u that while i is less then 5
remeber we are counting down
so what else should change here?
HINT: they want to count down until it hits 0

// Setup
var myArray = [];
// Only change code below this line
let i = 5;
while(i >= 0) {
  myArray.push(i);
  i--;
}

Hi Mat,
Awesome! just remember if you want to countdown you want to start with 5 all the way to 0, as your index, at the same time you decrement . Glad you work your way to get the problem solved. Happy Coding :slight_smile: