So I have been working on a game project where if a player clicks on a letter that if it matches in a phrase to guess, it displays the letter. If the player clicks on a letter without any matches (which is represented by null) then a blue heart turns to a lost heart and the missed counter goes up. For some reason, Even though the player clicks on a matching letter, my code still displays a lost heart. Can anyone help? Here is the github link to the whole project: https://github.com/santanaquan/Techdegree-Project-6
here is the javascript code snippet.
function checkLetter(button) {
const getLetter = document.getElementsByClassName('letter');
let letter;
for (let i = 0; i < getLetter.length; i++) {
if (button.textContent === getLetter[i].textContent) {
getLetter[i].className += ' show';
letter = getLetter[i].textContent;
}
else {
letter = null;
}
}
return letter;
}
nullwhen it shouldn't then you should place a script debugger breakpoint in that function and step through to observe its behavior. Somewhere you can narrow this down to a specific operation which first produces an unexpected result. What was that specific operation? What were the values used? What was the result? What result did you expect? Why?letter = getLetter[i].textContent;is missing abreakjust after so that it actually ends the loop when a letter is found rather than searching to the end of whatever the loop loops over and then returningnull.