-
-
Save codecademydev/ea395f09993b94a3ff5ddd338bc6e251 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
console.log('hi'); | |
const getUserChoice = userInput => { | |
userInput = userInput.toLowerCase(); | |
if (userInput === 'rock' || userInput === 'paper' || userInput === 'scissors') | |
return userInput | |
else { | |
console.log('ERROR'); | |
} | |
} | |
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 'The game was a tie.' | |
if (userChoice === 'rock' && computerChoice === 'scissors') | |
return 'The user is the winner!' | |
if (userChoice === 'rock' && computerChoice === 'paper') | |
return 'The computer is the winner!' | |
if (userChoice === 'paper' && computerChoice === 'rock') | |
return 'The user is the winner!' | |
if (userChoice === 'paper' && computerChoice === 'scissors') | |
return 'The computer has won' | |
if (userChoice === 'scissors' && computerChoice === 'paper') | |
return 'The user is the winner!' | |
if (userChoice === 'scissors' && computerChoice === 'rock') | |
return 'The computer has won' | |
} | |
const playGame = (determineWinner) => { | |
let userChoice = getUserChoice; | |
let computerChoice = getComputerChoice; | |
console.log(userChoice('ROCK'), getComputerChoice()) | |
} | |
console.log(playGame()) | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment