-
-
Save codecademydev/3227038061c73c5ffb416ae4617c189a 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('ERROR!'); | |
} | |
} | |
function determineWinner (userChoice, computerChoice) { | |
if (userChoice === computerChoice) { | |
return 'Game is a tie!' | |
} if (userChoice === 'rock') { | |
if (computerChoice === 'paper') { | |
return 'The computer won!'; | |
} else { | |
return 'You won!'; | |
} if (userChoice === 'paper') { | |
if (computerChoice === 'scissors') { | |
return 'The computer won!'; | |
} else { | |
return 'You won!'; | |
} if (userChoice === 'scissors') { | |
if (computerChoice === 'rock') { | |
return 'The computer won!'; | |
} else { | |
return 'You won!'; | |
} | |
} | |
} | |
} | |
} | |
//Testing Code | |
determineWinner(); | |
console.log(determineWinner('rock', 'rock')); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment