Play a single round of Rock Paper Scissors

This commit is contained in:
Synobbol 2023-01-17 16:11:00 +01:00
parent 9fa14ccf09
commit 97544cafe5

View File

@ -39,12 +39,38 @@ function getComputerChoice(){
return computer; return computer;
} }
console.log(getComputerChoice());
function playRound(playerSelection, computerSelection){ function playRound(playerSelection, computerSelection){
if (playerSelection = "rock" && computerSelection == "paper"){ let result = "It's a Tie!";
if (playerSelection === "rock" && computerSelection == "paper"){
console.log(playerSelection, computerSelection);
return result = "You Lose! Paper beats Rock";
}
else if(playerSelection === "paper" && computerSelection == "rock"){
console.log(playerSelection, computerSelection);
return result = "You Win! Paper beats Rock";
}
else if(playerSelection === "paper" && computerSelection == "scissors"){
console.log(playerSelection, computerSelection);
return result = "You Lose! Scissors beats Paper";
}
else if(playerSelection === "scissors" && computerSelection == "paper"){
console.log(playerSelection, computerSelection);
return result = "You Win! Scissors beats Paper";
}
else if(playerSelection === "rock" && computerSelection == "scissors"){
console.log(playerSelection, computerSelection);
return result = "You Win! Rock beats Scissors";
}
else if(playerSelection === "scissors" && computerSelection == "rock"){
console.log(playerSelection, computerSelection);
return result = "You Lose! Rock beats Scissors";
}
else{
console.log(playerSelection, computerSelection);
return result;
}
} }
else if(playerSelection = "paper" && computerSelection == "scissors") console.log(playRound("Paper", getComputerChoice()));
//"You Lose! Paper beats Rock"
}