在一个使用JavaScript的刽子手游戏中,当你还有3次猜测(生命)时,如何显示提示?

在一个使用JavaScript的刽子手游戏中,当你还有3次猜测(生命)时,如何显示提示?,javascript,Javascript,我是一个新手,在我的《刽子手》游戏中,我希望我的HTML代码在用户/玩家挣扎时出现在页面上,或者我应该说当用户/玩家还有3次猜测(生命)时出现在页面上。当用户只剩下3次猜测(生命)时,我希望它出现在页面上。我不知道怎么做。请帮忙。提前谢谢 这是我的提示HTML代码 <form> <input type="text" id="hint" value="Hint: words are web related." readonly></input>

我是一个新手,在我的《刽子手》游戏中,我希望我的HTML代码在用户/玩家挣扎时出现在页面上,或者我应该说当用户/玩家还有3次猜测(生命)时出现在页面上。当用户只剩下3次猜测(生命)时,我希望它出现在页面上。我不知道怎么做。请帮忙。提前谢谢

这是我的提示HTML代码

  <form>
     <input type="text" id="hint" value="Hint: words are web related." readonly></input>
  </form>

下面是我用来创建此页面的全部JavaScript代码

var wordbank = ['browser', 'binary', 'cache', 'cookie', 'CSS', 'HTML', 'javascript', 'gigabyte', 'google', 'download']
    var currentPlayingWord = "";
    var underscores = "";
    var guessCounter = 0;
    var livesLeft = 0;
    $(document).ready(function() {

    var randomWordIndex = randomNumber();
    currentPlayingWord = wordbank[randomWordIndex];
    underscores = wordloop(currentPlayingWord); 
    wordOutCome(underscores);
    guessCounter = 10;
    livesLeft = 10;

     $('#all-the-buttons button').click(function () {
      letterPress($(this));
     });



    });

    var wordloop = function(word){
      var wordcount = 0
      var underscores = "";
      while(wordcount < word.length) {
        underscores = underscores + "_";
        wordcount ++;
      }
      return underscores;
    }

    var randomNumber = function(){
      var random = Math.floor((Math.random() * 9) + 0);

      return random;
    }

    var wordOutCome = function(underscores){
      var wordoutcome = document.getElementById('word-outcome');
      wordoutcome.value = underscores;
    }

    function letterPress(button) {
                var text = button.text();
                if ("RESET" === text){
                  resetButton();
                }
                else { 
                  var currentText = $('#word-outcome').val();
                  //var output = currentText + text;

                  var result = isLetterInWord(text, currentPlayingWord);
                  if(result == true) {
                    replaceDashesForLetter(text);
                    var hasDashes = noMoreDashes();
                    if(hasDashes == true) {
                        navigateToWinnerPage();
                    }

                  }
                  else {
                    decreaseGuessCount();
                    noMoreGuesses();
                    addIncorrectGuessToWrongGuesses(text);
                    noMoreLives();
                  }


                  $('#word-outcome').val(underscores);

                }
    }

    function isLetterInWord(guess, word) {
      var uppercaseGuess = guess.toUpperCase();
      var uppercaseWord = word.toUpperCase();
      for (var i = 0; i < uppercaseWord.length; i++){
        console.log(i);
        if (uppercaseWord[i] === uppercaseGuess){
          return true; 
        }
        //get letter from word
        //is letter from word the same as guess
        //if letter from word is the same as guess return true
        //return false if guess is not in the word
      }
      return false;
    }

    function replaceDashesForLetter(letter) {
           for (var i = 0; i < currentPlayingWord.length; i++){
            console.log(currentPlayingWord);
            var playingLetter = currentPlayingWord[i];
            var upperCaseCurrentLetter = playingLetter.toUpperCase();
              if (upperCaseCurrentLetter == letter){
                underscores = setCharAt(underscores, i, letter);
              }
           }
              //for each letter in current word being played
            //does letter guessed match the letter in the current word
            //if letter guessed matches the letter in the current word - then replace the dash at the index (count in loop) with the letter guessed




      //for each of the letters in the word being played there is a dash
      //if the letter is at the index of a dash then replace that dash with the letter (which is the users guess)
    }

    function setCharAt(str,index,chr) {
      //get first part of word up to character we want to replace
      var first = str.substr(0,index);
      //get second part of word ONE letter AFTER character we want to replace
      var second = str.substr(index+1);
      //result is the first part plus the character to replace plus the second part
      return first + chr + second;
    }

    var addIncorrectGuessToWrongGuesses = function (guess) {
        var currentText = document.getElementById("wrong-guesses").value;
        document.getElementById("wrong-guesses").value = currentText + guess;
      //As the guess is wrong
      //add the guess to the list of incorrect guesses displayed on the screen
    }

    var greyOutButton = function (button) {
      //grey out the button
      //make sure that the user cannot press the button anymore
    }

    function resetButton () {

            location.href = "Hangman.html";

      //Send user to the home page
    }

    var decreaseGuessCount = function () {
      guessCounter = guessCounter - 1;
      livesLeft = livesLeft - 1;
    //guess count should be decreased by one 
    }

    var noMoreGuesses = function() {
      if (guessCounter === 0){
         location.href = "Looser Page.html";
      }
      //do something when no more guesses (navigate to loser page)
    }

    var noMoreDashes = function() {
        var i = underscores.indexOf("_");
        if (i > -1){
          return false;
        }
        return true;
      //if index of '_' is not -1 then there are dashes
    }

    var navigateToWinnerPage = function() {
      location.href = "Winner Page.html";
    }

    var noMoreLives = function() {
      var showLives = "You have " + livesLeft + " lives";
      var test = document.getElementById("mylives");
      test.textContent = showLives;

    }
var wordbank=['browser'、'binary'、'cache'、'cookie'、'CSS'、'HTML'、'javascript'、'gigabyte'、'google'、'download']
var currentPlayingWord=“”;
var下划线=”;
var计数器=0;
var-livesLeft=0;
$(文档).ready(函数(){
var randomWordIndex=randomNumber();
currentPlayingWord=wordbank[randomWordIndex];
下划线=字循环(currentPlayingWord);
文字结果(下划线);
猜测计数器=10;
livesLeft=10;
$(“#所有按钮”)。单击(函数(){
活版印刷($(本));
});
});
var wordloop=函数(字){
var wordcount=0
var下划线=”;
while(字数<字长){
下划线=下划线+“\”;
字数++;
}
返回下划线;
}
var randomNumber=函数(){
var random=Math.floor((Math.random()*9)+0);
返回随机;
}
var wordoutput=函数(下划线){
var-wordoutput=document.getElementById('word-output');
wordoutput.value=下划线;
}
功能活版印刷(按钮){
var text=button.text();
如果(“重置”==文本){
重置按钮();
}
否则{
var currentText=$(“#单词结果”).val();
//var输出=当前文本+文本;
var结果=IsleterInWord(文本,当前PlayingWord);
如果(结果==真){
替换字母DashesforLetter(文本);
var hasDashes=noMoreDashes();
if(hasDashes==true){
导航WinnerPage();
}
}
否则{
减少猜测计数();
noMoreGuesses();
将正确猜测添加到错误猜测(文本);
nomorelifes();
}
$(“#单词结果”).val(下划线);
}
}
函数(猜测,单词){
var uppercaseGuess=guess.toUpperCase();
var uppercaseWord=word.toUpperCase();
for(var i=0;i-1){
返回false;
}
返回true;
//如果“\u1”的索引不是-1,则存在破折号
}
var navigateToWinnerPage=函数(){
location.href=“Winner Page.html”;
}
var nomorelifes=函数(){
var showlifes=“您拥有”+livesLeft+“生活”;
var测试=document.getElementById(“mylives”);
test.textContent=showlifes;
}

在活版印刷函数的else“if result is true”(如果结果为真)中,将其添加到decreaseGuessCount之后

if (livesLeft === 3) alert('3 lives left');
另外,由于
if (result)
if (result == true)