Iterate with JavaScript While Loops

please what am I missing here, can’t get past this.
get error message `> myArray should equal [5, 4, 3, 2, 1, 0].

my code

// Setup
const myArray = ;
// Only change code below this line
let i=0;
while(i<=6){
myArray.push(i);
i++;
}

const myArray = [];
// Only change code below this line
let i=0;
while(i<=6){
myArray.push(i);
i++;
}

console.log(myArray)

/*
Output:

[
  0, 1, 2, 3,
  4, 5, 6
]
*/

you have minor bug in your logic

If you are going to build the array by pushing elements into it and the first number pushed into the array needs to be the number 5, what should be the first value of i? If the second number needs to be 4, what would you need to do to i to make the next number 4? Once you figure this out, you will solve this challenge.

1 Like

This topic was automatically closed 182 days after the last reply. New replies are no longer allowed.