From 97544cafe5b2779bf001652e3a684b494596c43f Mon Sep 17 00:00:00 2001 From: Synobbol <97944378+Synobbol@users.noreply.github.com> Date: Tue, 17 Jan 2023 16:11:00 +0100 Subject: [PATCH] Play a single round of Rock Paper Scissors --- script.js | 36 +++++++++++++++++++++++++++++++----- 1 file changed, 31 insertions(+), 5 deletions(-) diff --git a/script.js b/script.js index b2cb120..ab3775c 100644 --- a/script.js +++ b/script.js @@ -39,12 +39,38 @@ function getComputerChoice(){ return computer; } -console.log(getComputerChoice()); 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 == "scissors") - //"You Lose! Paper beats Rock" -} \ No newline at end of file + 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; + } + +} +console.log(playRound("Paper", getComputerChoice()));