Basic JavaScript - Iterate with JavaScript While Loops

`var myArray = ;
var i = 0;

while (i < 6) {
myArray.push(i);
1++;
}`
This is returning 012345 and NOT 543210 as required

var myArray = [];
var i = 0;

while (i < 6) {
  myArray.push(i);
  1++;
}

Your browser information:

User Agent is: Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:109.0) Gecko/20100101 Firefox/119.0

Challenge Information:

Basic JavaScript - Iterate with JavaScript While Loops

1 Like

Instead of 1++ , you should be incrementing i++ inside the while loop to increase the value of i

1 Like

I somehow copied incorrect code it should read as follows:
`var myArray = ;
var i = 0;

while (i < 6) {
myArray.push(i);
i++;
}`

Thanks for your reply. I noticed the error myself and rewrote (refactored?) the line and it is still not passing both tests - the log is returning 012345 and not 543210

2 Likes

you stil need to generate the array [5, 4, 3, 2, 1, 0] by using a while loop and pushing the values from 5 down to 0 into the myArray variable.

myArray.push(5 - i); // Appending values in reverse order

2 Likes

Thank you so much. I can now move on.

2 Likes