Skip to content

Instantly share code, notes, and snippets.

@codecademydev
Created November 7, 2020 12:23
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/0bae3d516e9c0bc47f4fb8f69fc2008c to your computer and use it in GitHub Desktop.
Save codecademydev/0bae3d516e9c0bc47f4fb8f69fc2008c 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('retype the input')
}
}
getComputerChoice = () => {
randomNumber = Math.floor(Math.random() *3)
if(randomNumber === 0 ) {
return 'rock';
} else if (randomNumber === 1) {
return 'paper';
} else {
return 'scissors';
}
}
determineWinner = (userChoice, computerChoice) => {
if (userChoice === computerChoice) {
return 'the game is tie';
} if (userChoice ==='rock' ) {
if (computerChoice ==='paper') {
return 'The computer won!';
} else {
return 'you are won!';
} if (userChoice ==='paper' && !computerChoice ==='paper') {
if (computerChoice ==='scissors') {
return "The computer won!";
} else {
return "You are won!";
} if (userChoice ==='scissors' && !computerChoice ==='scissors'){
if(computerChoice ==='rock'){
return "The computer won!";
}else {
return "You are won!";
}
}
}
}
console.log(determineWinner('rock','paper'))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment