Skip to content

Instantly share code, notes, and snippets.

@codecademydev
Created November 21, 2019 09:12
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save codecademydev/676808defef0877a641ebe045e01582d to your computer and use it in GitHub Desktop.
Save codecademydev/676808defef0877a641ebe045e01582d to your computer and use it in GitHub Desktop.
Codecademy export
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