I am trying to build a simple rock/paper/scissors game with JS. I am having trouble accumulating wins/losses. The game is working fine but for some reason wins losses are staying at 0 and are not adding at all. As you can see in the bellow code I have declared variables for wins/losses/draws and added wins++, losses++, draws++ in the appropriate cases. I added console log in the loop to be able to watch them update as I go through the game, however I am not sure why they are staying at 0. Any help would be greatly appreciated. Thank you
const options = [
"Rock",
"Paper",
"Scissors"
];
let wins = 0;
let losses = 0;
let draws = 0;
function computerPlay() {
var computerSelection = options[Math.floor(Math.random()*options.length)];
return computerSelection;
}
function playRound(playerSelection, computerSelection) {
computerSelection = computerPlay().toLowerCase();
if (computerSelection === "rock" && playerSelection === "paper") {
return("You win! Paper beats rock");
wins++;
}
else if (computerSelection === "scissors" && playerSelection === "paper") {
return("You lose! Scissors beats paper");
losses++;
}
else if (computerSelection === "scissors" && playerSelection === "rock") {
return("You win! Rock beats scissors");
wins++;
}
else if (computerSelection === "paper" && playerSelection === "rock") {
return("You lose! Paper beats rock");
losses++;
}
else if (computerSelection === "rock" && playerSelection === "scissors") {
return("You lose! Rock beats scissors");
losses++;
}
else if (computerSelection === "paper" && playerSelection === "scissors") {
return("You win! Scissors beats paper");
wins++;
}
else if (computerSelection === playerSelection){
return("Draw!");
draws++;
}
else {
return("Invalid Input!")
}
}
function game() {
let playerSelection
for(r = 1; r <= 5; r++) {
let computerSelection = computerPlay().toLowerCase()
playerSelection = prompt("rock, paper, or scissors?").toLowerCase();
result = playRound(playerSelection, computerSelection);
console.log(result);
console.log("wins: " + wins);
console.log("losses: " + losses);
console.log("draw: " + draws);
}
}
game();