Nested for loops, lesson 5


Hi. How to make both words ‘Barcelona’ and ‘Paris’ appear in a colon, not in a separate line???


I have this, and its works :slight_smile:

let myPlaces = [‘Barcelona’, ‘Honolulu’, ‘Paris’];
let friendPlaces = [‘New York’, ‘Paris’, ‘Barcelona’];

let matches = []

for (let myPlacesIndex = 0; myPlacesIndex < myPlaces.length; myPlacesIndex++) {

for (let friendPlacesIndex = 0; friendPlacesIndex < friendPlaces.length; friendPlacesIndex++) {

if (myPlaces[myPlacesIndex] === friendPlaces[friendPlacesIndex]) {


console.log(Match: + matches);


then use .join() on matches so it displays as string and not as array:


I have another problem :wink:

Its print: “Match: Barcelona,Paris”, but I wanna “Match: Barcelon, (space) Paris”.

How to do it?



.join() is ideal for that? You can decide on the characters between the elements of the arary


Thanks a lot stetim94, it was so easy but did it around :smiley:


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