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(){
|
function getComputerChoice(){
|
||||||
let compAnswer = Math.floor(Math.random() * 3) + 1;
|
let compAnswer = Math.floor(Math.random() * 3) + 1;
|
||||||
|
|
||||||
|
|
@ -26,6 +25,7 @@ function getComputerChoice(){
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
function playRound(playerSelection, computerSelection){
|
function playRound(playerSelection, computerSelection){
|
||||||
p = playerSelection.toLowerCase();
|
p = playerSelection.toLowerCase();
|
||||||
c = computerSelection.toLowerCase();
|
c = computerSelection.toLowerCase();
|
||||||
|
|
@ -56,6 +56,7 @@ function playRound(playerSelection, computerSelection){
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
function game() {
|
function game() {
|
||||||
if (pScore < 5 && cScore < 5) {
|
if (pScore < 5 && cScore < 5) {
|
||||||
const cs = getComputerChoice();
|
const cs = getComputerChoice();
|
||||||
|
|
@ -84,18 +85,14 @@ function game() {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
function endGame(){
|
|
||||||
if (pScore !== cScore) {
|
|
||||||
let winner = (pScore > cScore) ? true : false;
|
|
||||||
|
|
||||||
if (winner) {
|
function endGame(){
|
||||||
return "You won the game " + pScore + " to " + cScore + "! Great job!" ;
|
let winner = (pScore > cScore) ? true : false;
|
||||||
} else {
|
|
||||||
return "You lost the game " + pScore + " to " + cScore + ". Better luck next time!";
|
if (winner) {
|
||||||
}
|
return "You won the game " + pScore + " to " + cScore + "! Great job!" ;
|
||||||
} else if (cScore === 0) {
|
|
||||||
return "Uh... I don't think you played the game right. Refresh the page and try that again."
|
|
||||||
} else {
|
} 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