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:
Learn to code. Build projects. Earn certifications.Since 2015, 40,000 graduates have gotten jobs at tech companies including Google, Apple, Amazon, and Microsoft.
Hello~!
You currently have two errors:
You are counting up, when you should be counting down.
You’re excluding the value 5
from your loop.
Currently, you have two issues
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.
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?
Shadow2:
<
Adding this? Or something else?
The line
Shadow2:
while(i < 5) {
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