Skip to content

Instantly share code, notes, and snippets.

@njpatel
Created October 2, 2013 15:26
Show Gist options
  • Save njpatel/6795522 to your computer and use it in GitHub Desktop.
Save njpatel/6795522 to your computer and use it in GitHub Desktop.
RockPaperAaron.js
var options = [ "rock", "paper", "scissors" ];
var results = [ "wins!", "loses!", "draws!" ];
var compare = {
rock: {
rock: 2,
paper: 0,
scissors: 1
},
paper: {
rock: 1,
paper: 2,
scissors: 0
},
scissors: {
rock: 0,
paper: 1,
scissors: 2
}
};
var computerChoice = options[Math.floor(Math.random() / 0.33)];
var userChoice = prompt('Do you choose rock, paper or scissors?');
// Let's assume input has been validated :)
var result = compare[userChoice][computerChoice];
console.log(userChoice + ' ' + results[result]);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment