No idea what's wrong with this code, please help


#1

var myPlaces = [‘Hawaii’, ‘France’, ‘England’];
var friendPlaces = [‘Dubai’, ‘Antarctica’, ‘Sweden’];
for (var i = 0; i < myPlaces.length; i++) {
console.log(myPlaces[i]);
for (var j = 0; j < friendPlaces.length; j++) {
console.log(friendPlaces[j]);
if (myPlaces[i] === friendPlaces[j]) {
console.log('Match: ’ + myPlaces[i]);
} else {
console.log(‘Doesn’t match’);
}


#2

Hi, had a mess around with it for you. I commented what needed fixed. Hopefully that helps :slight_smile:

//punctuation - it's an array, but strings still have to be commented
var myPlaces = ['Hawaii', 'France', 'England']; //Include at least one of your countries to match
var friendPlaces = ['Dubai', 'France', 'Sweden']; // Your if statement will never run if there's no match.

for (var i = 0; i < myPlaces.length; i++) {
	console.log(myPlaces[i]);
for (var j = 0; j < friendPlaces.length; j++) {
	

  if (myPlaces[i] === friendPlaces[j]) {
	console.log(`Match: ${myPlaces[i]}`); //Syntax - make sure to use quotations properly
} 

}} //And finally, check your opening and closing for all code blocks :) 


#4

Comment deleted because I didn’t know the comment editor would delete leading spaces.


#5

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