From 4a172ea5c9ae912f465444b60981437d8edf3637 Mon Sep 17 00:00:00 2001 From: Saksham Mittal Date: Sat, 2 Apr 2022 21:13:34 +0530 Subject: Add limited tries --- script.js | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/script.js b/script.js index 43ab097..3f2d22e 100644 --- a/script.js +++ b/script.js @@ -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; + } } } } -- cgit 1.4.1