Why wouldn't this work to count backwards?

I am trying to count from 5 to 0… why this one wouldn’t work?

// Setup
const myArray = [];
let i = 6;

while (i < 6 && i > -1){
  myArray.push(i);
  i--;
}

// Only change code below this line

What is the value of i when you reach the while statement for the first time?

2 Likes

I see…

it worked this way…

// Setup
const myArray = [];
let i = 5;

while (i <= 5 && i > -1){
  myArray.push(i);
  i--;
}

// Only change code below this line

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