-
-
Save codecademydev/2b0b4255d240f9dda21493e1e831a8ce 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 userChoice = userInput => { | |
userInput = userInput.toLowerCase(); | |
if (userInput === 'rock' || userInput === 'paper' || userInput === 'scissors') { | |
return userInput; | |
} else if (userInput === 'bomb') { | |
return userInput; | |
} else { | |
console.log('There was an error.'); | |
} | |
} | |
if (userInput === 'bomb') { | |
return userInput | |
} | |
} | |
const compChoice = () => { | |
const randomNumber = (Math.floor(Math.random() * 3 )); | |
switch (randomNumber) { | |
case 0 : | |
return 'rock'; | |
break; | |
case 1 : | |
return 'paper'; | |
break; | |
case 2 : | |
return 'scissors'; | |
break; | |
} | |
} | |
const determineWinner = (getUserChoice, getCompChoice) => { | |
if (getUserChoice === 'bomb') { | |
return 'You won with the power of the bomb!' | |
} | |
if (getUserChoice === getCompChoice) { | |
return 'The game was a tie!'; | |
} | |
if (getUserChoice === 'rock') { | |
if (getCompChoice === 'paper') { | |
return 'The AI won!'; | |
} else { | |
return 'You won!'; | |
} | |
} | |
if (getUserChoice === 'paper') { | |
if (getCompChoice === 'scissors') { | |
return 'The AI won!'; | |
} else { | |
return 'You won!'; | |
} | |
} | |
if (getUserChoice === 'scissors') { | |
if (getCompChoice === 'rock') { | |
return 'The AI won!'; | |
} else { | |
return 'You won!'; | |
} | |
} | |
} | |
const playGame = () => { | |
const getUserChoice = userChoice('bomb'); | |
const getCompChoice = compChoice(); | |
console.log('You picked: ' + getUserChoice); | |
console.log('The AI picked: ' + getCompChoice); | |
console.log(determineWinner(getUserChoice, getCompChoice)); | |
} | |
playGame(); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment