Hi guys! After struggling for a LONG time on this challenge, I caved and checked the hint and found out that the reason my code wasn’t working was because I was using curly brackets after the if statement, like so:
if (word1.indexOf(word2[i]) === -1) { <------*
return false;
}
return true;
}
On the hint I saw that there was no curly brackets and as soon as I deleted the one after the if statement, my code worked…
My question is why do we not use curly brackets after the if statement here, because up until now I thought that an if statement has to be followed by a curly bracket?
Correct code (for context):
function mutation(arr) {
var word1 = arr[0].toLowerCase();
var word2 = arr[1].toLowerCase();
for (var i = 0; i < word2.length; i++) {
if (word1.indexOf(word2[i]) === -1)
return false;
}
return true;
}
mutation(["hello", "hey"]);
Link to the challenge: