出于某种原因,在用户猜对了数字并按照确认再次玩游戏但猜测次数较少(比原来少 2 次)后,每次用户猜测一个数字时,剩余的猜测数会减去 2,有时只是随机数通常的 1. 我尝试更改代码以各种不同的方式进行扣除,但无济于事:
j--;
j -= 1;
j = j - 1;
Fiddle中的完整代码,如果有人可以提供帮助,那将是很棒的,我已经在这几个小时了!谢谢
部分猜测按钮点击事件
if (currentGuess < numberToGuess) {
$hintBox.html('<p class="blue">Try higher</p>');
} else {
$hintBox.html('<p class="blue">Go lower</p>');
}
j = j - 1;
$('.numberGuesses').html(j);
} // end of if guess is not correct
else if (currentGuess === numberToGuess) {
alert('Well done the correct number was '+ numberToGuess);
var playAgain = confirm("Let's see if you can do that again with less guesses.");
if (playAgain){
$('#gameDiv').hide('pulsate', 100, function(){
$('#mode').delay(200).show('pulsate', 500);
});
lowerGuesses = lowerGuesses - 2;
$('.numberGuesses').html(lowerGuesses);
} else {
location.reload();
}
}