Forked from anonymous/Rock Paper Scissors v1 & v2 (1.4 TT).js
Created
July 31, 2016 17:24
-
-
Save sethschori/75c3e84e0ca314b8c0266658e2611176 to your computer and use it in GitHub Desktop.
https://repl.it/CXnp/45 created by sethopia
This file contains hidden or 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
/* | |
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')); |
This file contains hidden or 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
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