Skip to content

Instantly share code, notes, and snippets.

@codecademydev
Created November 29, 2021 02:15
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/8dd756f72f3fa5bed77d014dc44060d4 to your computer and use it in GitHub Desktop.
Save codecademydev/8dd756f72f3fa5bed77d014dc44060d4 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!');
}
};
console.log (getUserChoice ('rock'));
const getComputerChoice = () => {
const randomNumber = Math.floor(Math.random () * 3);
switch (randomNumber) {
case 0:
return 'rock';
case 1:
return 'paper';
case 2:
return 'scissors';
}
};
console.log(getComputerChoice());
console.log(getComputerChoice());
const determineWinner = (userChoice, computerChoice) => {
if (userChoice === computerChoice){{
return "It's a tie!";
}
if (userChoice === 'rock') {
if (computerChoice ==='paper') {
return "You lost!";
} else {
return "You win!";
}
}
if (userChoice === 'paper')
if (computerChoice === 'scissors'){
return "You lost!";
} else {
return "You win!";
}
if (userChoice==='scissors') {
if (computerChoice === 'rock') {
return "You lost!";}
else {return "You win!";
}
}
};
}
;
console.log (determineWinner ('rock', 'scissors'));
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment