-
-
Save codecademydev/676808defef0877a641ebe045e01582d to your computer and use it in GitHub Desktop.
Codecademy export
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
const getUserChoice = userInput = userInput => { | |
userInput = userInput.toLowerCase(); | |
if (userInput === 'rock'|| userInput === 'paper' || userInput === 'scissors'){ | |
return userInput; | |
} else { | |
console.log('Im sorry, you will have to enter either rock, paper, or scissors.'); | |
} | |
} | |
function getComputerChoice(){ | |
const compNum = Math.floor(Math.random() * 3); | |
if (compNum === 0){ | |
return 'scissors'; | |
} else if (compNum === 1){ | |
return 'paper'; | |
} else if (compNum === 2){ | |
return 'rock'; | |
} | |
} | |
function determineWinner(userChoice, computerChoice){ | |
if (userChoice === computerChoice){ | |
return 'The game is a tie.'; | |
} else if (computerChoice === 'rock'){ | |
if (userChoice !== 'paper'){ | |
return 'You lose!'; | |
} else { | |
return 'You win!'; | |
} | |
} else if (computerChoice === 'paper'){ | |
if (userChoice !== 'scissors'){ | |
return 'You lose!'; | |
} else { | |
return 'You win!'; | |
} | |
} else if (computerChoice === 'scissors'){ | |
if (userChoice !== 'rock'){ | |
return 'You lose!'; | |
} else { | |
return 'You win!'; | |
} | |
} | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment