{HELP} Learn Javascript Loops number 3


#1

So, I'm on this part of learn Javascript ( Instead of writing out the same code over and over, let’s make the computer loop through our array for us. We can do this with for loops.

The syntax looks like this:) It's asking me to make sure each result has its own console.log which I don't know how to do or if I did it wrong.

var vacationSpots = ['Poop land', 'Candy land', 'England'];

for (var i = 0; i < vacationSpots.length; i++) {
console.log('I would love to visit ' + vacationSpots[i]);

}
then when I hit run I'll get this error.

Did you console.log vacationSpots[i] within the for loop?

Which to me I did. If anyone could help me out with what I did wrong before the end of today that'd be great.


#2

Your code looks fine, but I think you've jumped ahead with the step-by-step instructions.

Delete your current console.log statement, and following the instructions in step 1, replace it with the more simple:

console.log(vacationSpots[i]);

Then click Run.

Assuming that works, move on to step 2 which is where you can change your console.log statement back to:

console.log('I would love to visit ' + vacationSpots[i]);

Then click Run again.

Remember to follow the steps exactly as described and use the Hints to guide you :slight_smile:


Loops JavaScript--- 3. For loops
#3

you better restart the session and try step by step process as shown in the instructions.

go to GET HELP and select "I want to restart this Exercise"

then write a for loop

for (var i = 0; i < vacationSpots.length; i++){
console.log(vacationSpots[i]);
}

above code executes the 1 step , and continue writing the below code for second step

for (var i = 0; i < vacationSpots.length; i++){
console.log('I would love to visit' + vacationSpots[i]);
}


#4

Thanks Mindful_coder!