HELP! Need help with this

Tell us what’s happening:
why is this not working?

Your code so far


var myArray = [];

var i = 0;
while(i < 5) {
myArray.push(i);
i++;
}

console.log(myArray);

Your browser information:

User Agent is: Mozilla/5.0 (Windows NT 6.1; ) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/83.0.4103.116 Safari/537.36.

Challenge: Iterate with JavaScript While Loops

Link to the challenge:

Hello~!

You currently have two errors:

  1. You are counting up, when you should be counting down.
  2. You’re excluding the value 5 from your loop. :slight_smile:

Currently, you have two issues

  1. You need to put the values in the array in descending order. If you want the numbers smaller, you can try decreasing your iterator instead of increasing it.

  2. You aren’t including the value 5 in your array, but its needed as well.

Well can you tell me how to solve it?

Well can you tell me how to solve it?

Well, to fix the first issue, how can you make i decrease instead of increase?

Adding this? Or something else?

The line

checks when you exit the ‘while’ loop. You will need to adjust this condition, but that will not make i decrease instead of increase.

To further build on @JeremyLT’s hint - how are you currently making i increase?

1 Like

All done thanks for the help

2 Likes

Good job figuring it out!

Thanks for helping! And Thanks

1 Like