newbie here! Just starting learning week and a half ago. Creating the rock paper scissors game. The goal is to play 5 rounds against the computer to determine the overall winner. I'm a little stumped when it comes to how I can award the player a point if they win or the computer a point if it wins. Also all critiques of code are welcome as well.
Thanks a ton!
code so far...
let array = ['rock', 'paper', 'scissor'];
const getComputerChoice = () => {
let random = Math.floor((Math.random() * 3));
let randomNames = array[random];
return randomNames;
}
const game = () => {
for (let i = 0; i < 5; i++) {
let input = prompt('Choose rock, paper or scissor');
const playerSelection = input.toLowerCase();
const computerChoice = getComputerChoice();
const computerWins = `Computer Wins! ${computerChoice} beats ${playerSelection}.`;
const playerWins = `Player wins! ${playerSelection} beats ${computerChoice}.`;
const tie = `It's a tie, ${playerSelection} is equal to ${computerChoice}.`;
if (playerSelection !== 'rock' && playerSelection !== 'paper' && playerSelection !== 'scissor') {
i = i - 1;
console.log("Nice try! Please enter a valid input.");
}
if (playerSelection === 'rock' && computerChoice === 'paper' || playerSelection === 'paper' && computerChoice === 'scissor' || playerSelection === 'scissor' && computerChoice === 'rock') {
console.log(computerWins);
}
if (playerSelection === 'paper' && computerChoice === 'rock' || playerSelection === 'scissor' && computerChoice === 'paper' || playerSelection === 'rock' && computerChoice === 'scissor') {
console.log(playerWins);
} else {
if (playerSelection === computerChoice) {
console.log(tie);
}
}
}
}
game();
just add variable of score and increment after each win