Iterate with javaScript while loop

please help!! how do i add the numbers 5 through 0 (inclusive) in descending order to myArray using a this while loop. I’m stuck!!

   **Your code so far**

// Setup
var myArray = [];
var i = 0; 
while(i <= 6 ) {
// 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/91.0.4472.124 Safari/537.36

Challenge: Iterate with JavaScript While Loops

Link to the challenge:

your loop now creates an array with numbers from 0 to 6, there are two things to do

  1. Make so that the numbers stop/start at 5, not 6
  2. Have the numbers in reverse order, which can be done in two ways
    • You could change array method so that the numbers are added at the beginning of the array, so that you have [0]. then the next one is added at the beginning so [1, 0] etc
    • OR you could change how i is treated, its starting point, the loop condition and how it is updated

The first method @ilenia mentioned will work well with your current code, but I would recommend the second method as appending things to the end of an array is more performant.

Thanks dear. i ve been able to clear it. wow!, thanks so much dear.

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