-
-
Save codecademydev/0d438544b73fa4a73b60b8436b4d3374 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 message. please try it later'); | |
} | |
} | |
console.log(getUserChoice('paper'));//should print 'paper' | |
console.log(getUserChoice('12'))//should print 'error~'and undefined | |
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 'tie'; | |
} else if(userChoice === 'rock' && computerChoice === 'paper'){ | |
return 'computer won'; | |
} else { | |
return 'user won'; | |
} | |
if (userChoice === 'scissors' && computerChoice === 'rock'){ | |
return 'computer won'; | |
} else { | |
return 'user won'; | |
} | |
if (userChoice === 'paper' && computerChoice === 'scissors'){ | |
return 'computer won'; | |
} else { | |
return 'user won'; | |
} | |
}; | |
console.log(determineWinner('scissors', 'rock')); | |
console.log(determineWinner('paper', 'scissors')); | |
console.log(determineWinner('rock', 'paper')); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment