Nested For Loops 6/8 - Code not displaying in console

I’ve completed this lesson, but nothing is actually showing the console. I want to understand if there is anything wrong with my code, or a bug with the lesson.


let myPlaces = ['USA','Spain','Paris'];
let friendPlaces = ['China','Japan','Italy'];

for (let myPlacesIndex = 0; myPlacesIndex < myPlaces.length; myPlacesIndex++){
for (let friendPlacesIndex = 0; friendPlacesIndex < friendPlaces.length; friendPlacesIndex++){
if (myPlaces[myPlacesIndex] === friendPlaces[friendPlacesIndex]){
    console.log('Match ' + myPlaces[myPlacesIndex]);

only if you and your friend visit the same place, its log to the console that there is a match

you and your friend haven’t visited the same place, so no match, so nothing is logged


Right, that makes sense. So ideally I would right an else if statement to be something like ‘There was no match this time’.

we can’t just insert an else if statement, because that would then log each iteration of the loop

then we would need to create a variable (for example match), and set it to false

then if there is a match (within the if clause), set match to true

then after the loop check the value of match, and if there is no match, log that there where no matches found


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