-
-
Save codecademydev/0bae3d516e9c0bc47f4fb8f69fc2008c to your computer and use it in GitHub Desktop.
Codecademy export
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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