Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
Codecademy export
const getUserChoice = userInput => {
userInput = userInput.toLowerCase();
if ((userInput === 'rock') || (userInput === 'paper') || (userInput === 'scissors')) {
return userInput;
} else {
console.log('Error, invalid term entered.');
}
};
const getComputerChoice = () => {
let randomNumber = Math.floor(Math.random() * 3);
if (randomNumber === 0) {
return 'rock';
} else if (randomNumber === 1) {
return 'paper';
} else if (randomNumber === 2) {
return 'scissors';
} else {
return 'error';
}
};
const determineWinner = (userChoice, computerChoice) => {
if (userChoice === computerChoice) {
return 'The game is a tie!';
}
if (userChoice === 'rock') {
if (computerChoice === 'paper') {
return 'You lose!';
} else {
return 'You win!';
} else if (userChoice === 'paper') {
if (computerChoice === 'rock') {
return 'You win!';
} else {
return 'You lose!';
} else if (userChoice === 'scissors') {
if (computerChoice === 'rock') {
return 'You lose!';
} else {
return 'You win!';
}
} else {
return 'error';
}
};
console.log(determineWinner('rock', 'paper'));
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.