Basic JavaScript - Iterate with JavaScript While Loops

Tell us what’s happening:
Describe your issue in detail here.
Challenge asks for the sequence in descending order hence why I started at 6 and took away 1 until ‘i’ was less than 0
Your code so far

// Setup
const myArray = [];

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


Your browser information:

User Agent is: Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/109.0.0.0 Safari/537.36

Challenge: Basic JavaScript - Iterate with JavaScript While Loops

Link to the challenge:

let’s look at these two lines for a bit.

1st one tells the computer that i should be set to an initial value of 6. We agree so far.
2nd line starts a while loop.
The while only runs if the condition in the brackets is true. So what does the condition in the bracket evaluate to when i is set to 6?

I understand, I have no set it to

while (i >= 0)

so it runs until it would hit -1 and stop however, it still does not work.

I got it figured out. I changed it so

i = 5

to start so it would run one less time

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