From 71b2f9254d2d50362fbfb65217ce24de5ec98c94 Mon Sep 17 00:00:00 2001 From: Albin <142149906+mkdew37@users.noreply.github.com> Date: Thu, 18 Apr 2024 13:32:30 +0200 Subject: [PATCH] Fixed issue where player and computer score didnt reset when reset button was clicked --- javascript.js | 19 +++++++++++++++---- 1 file changed, 15 insertions(+), 4 deletions(-) diff --git a/javascript.js b/javascript.js index df64030..d5c9ed9 100644 --- a/javascript.js +++ b/javascript.js @@ -84,10 +84,10 @@ function displayGameResult(playerScore, computerScore, announceWinner) { return announceWinner.innerText = `Congratulations! You won the game with a score of ${playerScore} to ${computerScore}!`; } else if (playerScore < computerScore) { - return announceWinner.innerText = `You lose the game with a score of ${playerScore} to ${computerScore}!`; + return announceWinner.innerText = `You lost the game with a score of ${playerScore} to ${computerScore}!`; } else { - return announceWinner.innerText = "It's a tie! Try harder next time.
"; + return announceWinner.innerText = "It's a tie! Try harder next time."; } } @@ -121,9 +121,18 @@ function playRound(playerSelection) { } function playGame() { - if (playerScore >= winningScore || computerScore >= winningScore) { + if (playerScore < winningScore && computerScore < winningScore) { + + } else { + + if (playerScore > computerScore) { return displayGameResult(playerScore, computerScore, announceWinner); -} + } else if (playerScore < computerScore) { + return displayGameResult(playerScore, computerScore, announceWinner); + } else { + return displayGameResult(playerScore, computerScore, announceWinner); + } + } } //Event listeners @@ -152,6 +161,8 @@ btnScissor.addEventListener('click', () => { const btnReset =document.querySelector('#restartGame'); btnReset.addEventListener ('click', () => { + playerScore = 0; + computerScore = 0; playerDisplayScore.innerText = 0; computerDisplayScore.innerText = 0; playerImage.src = '';