-
-
Save codecademydev/7414968f797cea412715a0e7c3ffbd6b 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 === 'scissors' || userInput === 'paper') { | |
return userInput; | |
} else { | |
console.log('Error, please type: rock, paper, 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 'This game is a tie!'; | |
} | |
if (userChoice === 'rock') { | |
if (computerChoice === 'paper') { | |
return "Sorry,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 "Congratulations, you won!"; | |
} | |
} | |
} | |
console.log(determineWinner('rock',\ 'scissors')); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment