Another clue, you āpushā to the end of an array. You can do the opposite and place your values to the front of the array. That will decrease the values.
Ive now tried this method and gotten the correct numbers in the array, however I am still unsure how to make it count from 5 downwards, rather than from 0 upwards?
// Setup
var myArray = [];
// Only change code below this line
var i = 0;
while(i < 6) {
myArray.push(i);
i++;
}
console.log(myArray)
You already said how to make the variable decrease.
but you need to
Iāve edited your post for readability. When you enter a code block into a forum post, please precede it with a separate line of three backticks and follow it with a separate line of three backticks to make it easier to read.
You can also use the āpreformatted textā tool in the editor (</>) to add backticks around text.
Another clue, you āpushā to the end of an array. You can do the opposite ā¦
Right, that would work, but the the instructions explicitly mention āpushingā. The purpose of the lesson is to learn about while loops, not to explore prototype methods.
Since i starts out at 6, it starts out above 0 and fails the while test before it even begins. Instead of checking it it is less than 0, you should loop it while it is ā¦
I wrapped it in spoiler tags since it is a working solution.
The only thing I would have done a little differently is that instead of running the loop while i is greater than -1, I would have looped it while i is greater than or equal to 0. Since weāre dealing with integers, the effect is the same, but semantically it makes more sense to me since 0 is what weāre targeting here, not -1. But yeah, they both work the same in this case.
Take a second and read through the code and understand how those three steps interact - initializing the index variable, checking the indexing variable, changing the indexing variable.