Basic JavaScript - Iterate with JavaScript While Loops

Tell us what’s happening:
I have followed the steps and believe i did everything right. However its still not returning the string {5,4,3,2,1,0] can someone help me figure out what i am doing wrong please. I keep getting just one number for an answer.

Your code so far

// Setup
const myArray = [];

// Only change code below this line

let i = 5;
while (i < 0) {
  myArray.push(i);
  i--;
}

Your browser information:

User Agent is: Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/115.0.0.0 Safari/537.36

Challenge: Basic JavaScript - Iterate with JavaScript While Loops

Link to the challenge:

I would suggest adding this console statement to see what your array looks like

console.log(myArray)

Then take a close look at your condition here

If i is set to 5, then it will never be less then 0 so the condition never runs.
Once you fix the condition, then it will pass.

oooh. Okay that makes sense! Iwas able to fix it and complete the step. Thank you for helping me figure things out.

1 Like

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