From ca3064dfda25949f0b4fbaa3c8f13e078b9fc26b Mon Sep 17 00:00:00 2001 From: lolabird Date: Tue, 7 Nov 2023 21:35:33 -0700 Subject: [PATCH] Remove unnecessary conditionals from endGame --- script.js | 21 +++++++++------------ 1 file changed, 9 insertions(+), 12 deletions(-) diff --git a/script.js b/script.js index 9f33e94..0d7dd1f 100644 --- a/script.js +++ b/script.js @@ -13,7 +13,6 @@ buttons.forEach((button) => { }); - function getComputerChoice(){ let compAnswer = Math.floor(Math.random() * 3) + 1; @@ -26,6 +25,7 @@ function getComputerChoice(){ } } + function playRound(playerSelection, computerSelection){ p = playerSelection.toLowerCase(); c = computerSelection.toLowerCase(); @@ -56,6 +56,7 @@ function playRound(playerSelection, computerSelection){ } } + function game() { if (pScore < 5 && cScore < 5) { const cs = getComputerChoice(); @@ -84,18 +85,14 @@ function game() { } } -function endGame(){ - if (pScore !== cScore) { - let winner = (pScore > cScore) ? true : false; - if (winner) { - return "You won the game " + pScore + " to " + cScore + "! Great job!" ; - } else { - return "You lost the game " + pScore + " to " + cScore + ". Better luck next time!"; - } - } else if (cScore === 0) { - return "Uh... I don't think you played the game right. Refresh the page and try that again." +function endGame(){ + let winner = (pScore > cScore) ? true : false; + + if (winner) { + return "You won the game " + pScore + " to " + cScore + "! Great job!" ; } else { - return "Whoa, you tied! Refresh for a rematch!"; + return "You lost the game " + pScore + " to " + cScore + ". Better luck next time!"; } + } \ No newline at end of file