Need help with creating a guessing limit for a word guessing game

I have made a word guessing game and I need a way to have a limit for the number of times someone can guess the word.

  • I need to use && to check if the two Boolean conditions are true

  • A variable needs to be added to track the players’ number of guesses

Here is where that code should be because this is that part of code that get players input


      

    //Code below shows player's progress

    alert(answerArray.join(""));

//Lines of code below is for getting a guess from the player, lowercasing and limit of trys

var guess = prompt("Guess a letter, or click Cancel to stop playing.");

guess = guess.toLowerCase();

if (guess === null && ) {

    //For exiting the game, if cancel is pressed

    break;

} else if (guess.length !== 1) {

    alert("Please enter a single letter.");  

} else {

    for (var j = 0; j < word.length; j++) {

        if (word[j] === guess) {

            answerArray[j] = guess;

            remainingLetters--;

            }

        }

    }

}

You should create a constant that hold the maximum guess you want for a session of the game. You then create a variable that will be counting the guesses of the user. If user guesses == max guess, end the game (session).

Hope that this can help you. If you need the code, let me know.

Ok, Do I add it inside the condition like this? if (guess === null && guess == 5)?

Oh that doesn’t work, I’m not sure how to add it.

I got help from another place, and it works now.