Skip to content

Instantly share code, notes, and snippets.

@codecademydev
Created January 12, 2023 22:50
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save codecademydev/ea395f09993b94a3ff5ddd338bc6e251 to your computer and use it in GitHub Desktop.
Save codecademydev/ea395f09993b94a3ff5ddd338bc6e251 to your computer and use it in GitHub Desktop.
Codecademy export
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