Remove unnecessary conditionals from endGame
This commit is contained in:
parent
3c37c3447e
commit
ca3064dfda
1 changed files with 8 additions and 11 deletions
21
script.js
21
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!";
|
||||
}
|
||||
|
||||
}
|
||||
Loading…
Reference in a new issue