Still waiting for the New York Times to send me a bogus takedown notice
Add limited tries
| -rw-r--r-- | script.js | 7 |
1 files changed, 7 insertions, 0 deletions
@@ -1,4 +1,5 @@ let answer = "hello"; +let maxtries = 6; let len = answer.length; let input = document.querySelector('input'); @@ -69,6 +70,7 @@ function checkAnswer(event) { if (validateInput()) { addGuessDisplay(); tries++; + if (input.value == answer) { win.innerHTML = "You won!"; exit = true; @@ -80,6 +82,11 @@ function checkAnswer(event) { if (tries > 1) { attempt.innerHTML += "s"; } + + if (tries > maxtries) { + win.innerHTML = "You lost! Better luck next time!"; + exit = true; + } } } } |