Created
March 23, 2016 01:58
-
-
Save mindplace/a7fb6705d7a88acc10ef to your computer and use it in GitHub Desktop.
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
| function rockPaperScissors(string) { | |
| var options = { | |
| 1: "Rock", | |
| 2: "Paper", | |
| 3: "Scissors", | |
| }; | |
| var judge = { | |
| "Function wins!": [["Rock", "Paper"], ["Paper", "Scissors"], ["Scissors", "Rock"]], | |
| "You win!": [["Paper", "Rock"], ["Scissors", "Papers"], ["Rock", "Scissors"]], | |
| "Aww, a draw...": [["Paper", "Paper"], ["Rock", "Rock"], ["Scissors", "Scissors"]] | |
| }; | |
| var functionMove = options[Math.floor((Math.random() * 3) + 1)]; | |
| var moves = [string, functionMove].join(" ") | |
| var message = ""; | |
| for (var elem in judge) { | |
| var group = judge[elem]; | |
| for (var i=0; i < group.length; i++) { | |
| var potential = group[i].join(" ") | |
| if (moves === potential) { | |
| message = elem; | |
| break; | |
| } | |
| } | |
| } | |
| console.log("You played " + string + ", function played " + functionMove + ": " + message) | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment