Skip to content

Instantly share code, notes, and snippets.

@codecademydev
Created February 18, 2021 15:52
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/7e2c200ee8654f319afddbe8cc3f0e96 to your computer and use it in GitHub Desktop.
Save codecademydev/7e2c200ee8654f319afddbe8cc3f0e96 to your computer and use it in GitHub Desktop.
Codecademy export
const getUserChoice = userInput => {
usersInput = userInput.toLowerCase();
if (userInput === 'rock'|| userInput ==='paper'|| userInput === 'sissors'){
return userInput;
}
else {
console.log ('Error: You must enter either \"rock\", \"paper\" or \"sissors\"');
}
}
//console.log(getUserChoice('rock'))
//console.log(getUserChoice('potato'))
const getComputerChoice = () => {
const randomNumber = Math.floor(Math.random() * 3);
switch (randomNumber) {
case 0:
return 'rock';
case 1:
return 'paper';
case 2:
return 'siccors';
}
};
//console.log(getComputerChoice())
//console.log(getComputerChoice())
//console.log(getComputerChoice())
//console.log(getComputerChoice())
const determineWinner = (userChoice, computerChoice) => { if (userChoice === computerChoice){return 'This game is a tie!';}
if (userChoice === 'rock') {
if (computerChoice === 'paper'){
return "Sorry, the computer won!";}
else {
return "You won!";}
}
}
if (userChoice === 'paper') {
if (computerChoice === 'siccors'){
return "Sorry, the computer won!";} else {return "You won!";}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment