Skip to content

Instantly share code, notes, and snippets.

@codecademydev
Created May 30, 2020 01: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/b963a3b1d7ebc906deb4eb8ec2326850 to your computer and use it in GitHub Desktop.
Save codecademydev/b963a3b1d7ebc906deb4eb8ec2326850 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, Please type 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 = (userChoice, ComputerChoice) => {
if (userChoice === computerChoice) {
return 'The game is a tie!';
}
if (userChoice === 'rock') {
if (computerChoice === 'paper') {
return "Sorry, the computer won!";
} else {
return "Congratulations, you won!";
}
}
}
if (userChoice === 'paper') {
if (computerChoice === 'scissors') {
return "Sorry, computer won!";
} else {
return "Congratulations, you won!";
}
}
if (userChoice === 'scissors') {
if (computerChoice === 'rock') {
return "Sorry, computer won!";
} else {
return "Congratu;ations, you won!";
}
};
console.log(determineWinner('rock', 'scissors'));
console.log(determineWinner('paper', 'scissors'));
console.log(determineWinner('rock', 'rock'));
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment