Skip to content

Instantly share code, notes, and snippets.

@codecademydev
Created June 25, 2020 22:58
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/8ecddbfae6e0596802802a055cb18b79 to your computer and use it in GitHub Desktop.
Save codecademydev/8ecddbfae6e0596802802a055cb18b79 to your computer and use it in GitHub Desktop.
Codecademy export
const getUserChoice = userInput => {userInput = userInput.toLowerCase()
if (userInput === 'rock' || userInput === 'paper' || userInput === 'scissors') {return userInput;} else {console.log('Error! Insert: rock, paper, or scissors.')};
}
const getComputerChoice = () => {const randomNumber = Math.floor(Math.random() * 3);
switch (randomNumber) {case 0: return 'rock'; case 1: return 'paper'; case 2: return 'scissors'};}
const determineWinner = (getUserChoice, getComputerChoice) => {if (getUserChoice === getComputerChoice) {return 'The game is a tie!';}
if (getUserChoice === 'rock') {if (getComputerChoice === 'paper') {return 'Sorry, computer Won!';} else {return 'Congrats, you won!';}
if (getUserChoice === 'paper') {if (getComputerChoice === 'scissors'){return 'Sorry, computer Won!';} else {return 'Congrats, you Won!';}}
if (getUserChoice === 'scissors') {if (getComputerChoice === 'rock'){return 'Sorry, computer Won!';} else {return 'Congrats, you Won!';}}
}
const playGame = () => {const userChoice = getUserChoice('paper');
const computerChoice = getComputerChoice();
console.log('You threw' + userChoice);
console.log('The computer threw' + computerChoice);
console.log(determineWinner(userChoice, computerChoice))
};
playGame()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment