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:
Learn to code. Build projects. Earn certifications.Since 2015, 40,000 graduates have gotten jobs at tech companies including Google, Apple, Amazon, and Microsoft.
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:
Learn to code. Build projects. Earn certifications.Since 2015, 40,000 graduates have gotten jobs at tech companies including Google, Apple, Amazon, and Microsoft.
Learn to code. Build projects. Earn certifications.Since 2015, 40,000 graduates have gotten jobs at tech companies including Google, Apple, Amazon, and Microsoft.
Yes I have reviewed those lessons just it doesn’t make sense to put those in the function
Well the loop says
MaverickYT:
while(i < 5) {
and i
starts at
MaverickYT:
var i = 0;
and inside the loop you
MaverickYT:
i++;
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:
For years people have asked freeCodeCamp to create a Discord chat. Well today,
I'm excited to announce that we did it. We now have an official Discord chat
room server.
Before you join, please give me 2 minutes to explain our goals with this...
link at the bottom of the article