Skip to content

Commit

Permalink
Fixed issue where player and computer score didnt reset when reset bu…
Browse files Browse the repository at this point in the history
…tton was clicked
  • Loading branch information
mkdew37 committed Apr 18, 2024
1 parent 80fc6e5 commit 71b2f92
Showing 1 changed file with 15 additions and 4 deletions.
19 changes: 15 additions & 4 deletions javascript.js
Original file line number Diff line number Diff line change
Expand Up @@ -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.<br>";
return announceWinner.innerText = "It's a tie! Try harder next time.";
}
}

Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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 = '';
Expand Down

0 comments on commit 71b2f92

Please sign in to comment.