diff --git a/javascript/introduction-to-js-1/troubleshooting/number-game-errors.html b/javascript/introduction-to-js-1/troubleshooting/number-game-errors.html index cae7f55a3..3a01026ef 100644 --- a/javascript/introduction-to-js-1/troubleshooting/number-game-errors.html +++ b/javascript/introduction-to-js-1/troubleshooting/number-game-errors.html @@ -23,94 +23,92 @@ -

Number guessing game

- -

We have selected a random number between 1 and 100. See if you can guess it in 10 turns or less. We'll tell you if your guess was too high or too low.

- -
- - - -
- -
-

-

-

-
- - - - + guessSubmit.addeventListener('click', checkGuess); + + function setGameOver() { + guessField.disabled = true; + guessSubmit.disabled = true; + resetButton = document.createElement('button'); + resetButton.textContent = 'Start new game'; + document.body.appendChild(resetButton); + resetButton.addeventListener('click', resetGame); + } + + function resetGame() { + guessCount = 1; + + const resetParas = document.querySelectorAll('.resultParas p'); + for (const resetPara of resetParas) { + resetPara.textContent = ''; + } + resetButton.parentNode.removeChild(resetButton); + + guessField.disabled = false; + guessSubmit.disabled = false; + guessField.value = ''; + guessField.focus(); + + lastResult.style.backgroundColor = 'white'; + + randomNumber = Math.floor(Math.random()) + 1; + } + +