何らかの理由で、ユーザーが正しい数字を推測し、確認に従ってゲームを再度プレイした後、推測が少なくなります(元の数字より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();
}
}