Skip to content

Instantly share code, notes, and snippets.

@mindplace
Created March 23, 2016 01:58
Show Gist options
  • Select an option

  • Save mindplace/a7fb6705d7a88acc10ef to your computer and use it in GitHub Desktop.

Select an option

Save mindplace/a7fb6705d7a88acc10ef to your computer and use it in GitHub Desktop.
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