5. For Loops Inside For Loops

<PLEASE USE THIS TEMPLATE TO HELP YOU CREATE A GREAT POST!>

<Below this line, add a link to the EXACT exercise that you are stuck at.>
https://www.codecademy.com/en/courses/learn-javascript/lessons/loops/exercises/for-loops-iii

<Below this line, in what way does your code behave incorrectly? Include ALL error messages.>
“Did you write an if/else statement inside the second for loop?”

```

var myPlaces = [“a”, “b”, “c”];
var friendPlaces = [“d”, “a”, “e”];
for(var i = 0; i < myPlaces.length; i++) {
console.log(myPlaces[i]);
for(var j = 0; j < friendPlaces.length; j++) {
if (myPlaces[i] == friendPlaces[i]) {
console.log(myPlaces[i]);
};
};
};

<do not remove the three backticks above>
1 Like

Oh my god. facepalm

Just realised my mistake and fixed it. Gosh, JS can be so intricate haha.

In the condition of the if statement, I changed ‘==’ to ‘===’ AND I changed ‘friendPlaces[i]’ to ‘friendPlaces[j]’.

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