Stuck in Basic JavaScript (93)

Tell us what’s happening:

Hello so pretty much I watched the video and this isn’t working I do not understand what I am supposed to do from now cause I copied the entire video guide and its giving me an error…

Your code so far


// Setup
var myArray = [];

// Only change code below this line

var i = 0;

while(i < 5) {
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/84.0.4147.135 Safari/537.36.

Challenge: Iterate with JavaScript While Loops

Link to the challenge:

What error are you encountering? What else have you tried?

you should reverse
var i=5
and while(i >=0 ) and decrement the i inside the loop, i-- (because your arr must be myArray=[5,4,3,2,1,0])

Well would you mind explain the entire for loop? cause its weird like what does the i++ & i-- do like what?

I think you may have overlooked these two previous lessons:

Yes I have reviewed those lessons just it doesn’t make sense to put those in the function

Well the loop says

and i starts at

and inside the loop you

So you repeat the contents of the loop, increasing i while the loop condition (i < 5) is true.

I just want to know why we are incrementing the i variable

If we didn’t increment the i variable, then i < 5 would always be true and the loop would run forever.

oh BECAUSE i is set to 0 so after we increment the variable, i will = 1

1 Like

Right, and then the loop will increment again and again until i === 5

See here:

do you have discord and you can possibly assist me?

freeCodeCamp has a Discord:


link at the bottom of the article