I don’t know if something is wrong with the function but my hero says the spy name as a friend no matter what.
here is my code:
function letterInWord(word, letter) {
for (var i = 0; i < word.length; i++) {
var character = word[i];
if (character == letter) {
return true;
}
return false;
}
}
var spyLetter = "z";
var friends = hero.findFriends();
for (var j = 0; j < friends.length; j++) {
var friendName = friends[j].id;
if (letterInWord(friendName, spyLetter)) {
hero.say(friendName + " is a spy!!!");
} else {
hero.say(friendName + " is a friend.");
}
}