Hello, I am a beginner in programming and I am currently working on developing a word guessing game. Here is the code I have written so far:
- The (letter) represents the key being typed by the player
- Var compareLetters = $('.letter') represents the empty boxes at the top
- Const game = new Game() creates a new instance of a class constructor named Game, which includes a property called this.phrases containing an array of phrases
showMatchedLetter(letter) {
// If there was a match on the checkLetter method, add a show-letter class
// Grab letters and store them in a variable
var compareLetters = $('.letter');
// Create a new game instance to access the array property for the loop below
const game = new Game()
// Assign the phrase array to a variable for reference
const phraseArray = game.phrases;
console.log(phraseArray)
/* Use the each method to iterate through the array of Phrase characters,
and compare each character to the letter selected by the player.
*/
compareLetters.each((i, compareLetters) => {
if ($(compareLetters).text() === letter) {
$('.letter').addClass('show letter');
}
});
}
I am working to reveal the correct letters guessed by the player. Although my code functions, I am encountering an issue where instead of just showing the matching letters, the entire phrase is revealed. Can someone please assist me with this?