Having problems with for loops inside for loops


#1


https://www.codecademy.com/courses/learn-javascript/lessons/loops/exercises/for-loops-iii?action=lesson_resume&link_content_target=interstitial_lesson


This is the error "Did you a for loop that loops over the myPlaces array?"

i'm at the third step of this exercise, i think it's a bug, because when i run the code, it prints in the screen and nothing seems wrong, just that message and the fact that the step is marked with an x.

var myPlaces = ['1m','2m','3m'];
var friendPlaces = ['1f','2f','3f'];
for (var A = 0; A < myPlaces.length; A++)
{
  console.log(myPlaces[A]);
}


#2

Here:

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

This code has two problems:
1. The { should be on the same line as the for statement...
2. The console.log statement should be indented four spaces, not two.

Both of these issues are syntax related, fix them and you should be good.

TL;DR... Your code uses improper syntax. It should look like this:

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

#3

Thanks but i still have the same problem. I already rewrote the code 128738175892739 times and idk what to do, i'm totally stuck.
EDIT: fixed, i don't know what happened but after i copied and pasted my own code a few times, it just worked.


#4

This topic was automatically closed 7 days after the last reply. New replies are no longer allowed.