Skip to content

Instantly share code, notes, and snippets.

Created July 31, 2016 17:21
Show Gist options
  • Save anonymous/c16e01ad8f7b21ebfb3ed8fb7238f69f to your computer and use it in GitHub Desktop.
Save anonymous/c16e01ad8f7b21ebfb3ed8fb7238f69f to your computer and use it in GitHub Desktop.
https://repl.it/CXnp/45 created by sethopia
/*
Thoughtful Thursdays - RPS
*/
function rockPaperScissors(hand1, hand2) {
// hand1 equals hand2, return 'tie'
if (hand1 === hand2) {
return 'TIE';
}
if (hand1 === 'rock' && hand2 === 'paper' ||
hand1 === 'paper' && hand2 === 'scissors' ||
hand1 === 'scissors' && hand2 === 'rock') {
return 'player2';
}
return 'player1';
}
console.log(rockPaperScissors('rock', 'rock'));
console.log(rockPaperScissors('paper', 'rock'));
console.log(rockPaperScissors('scissors', 'rock'));
console.log(rockPaperScissors('scissors', 'paper'));
Native Browser JavaScript
>>> TIE
player1
player2
player1
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment