Skip to content

Instantly share code, notes, and snippets.

@clavery
Forked from joehinkle/RPS.js
Last active December 21, 2015 21:39
Show Gist options
  • Save clavery/6370251 to your computer and use it in GitHub Desktop.
Save clavery/6370251 to your computer and use it in GitHub Desktop.
// Initializing Variables
var selection = prompt("Do you choose rock, paper or scissors?");
var PLAYS = ['scissors', 'paper', 'rock'];
var mine = PLAYS.indexOf(selection);
if(mine < 0) {
console.log("Bad play!!");
return;
}
var computer = Math.floor(Math.random() * 3);
var result = ((mine + 1) % 3) === computer;
if(mine === computer)
console.log("You Tie");
else if(result)
console.log("You Win");
else
console.log("You Lose");
@jdkeith
Copy link

jdkeith commented Aug 28, 2013

I really like the modulo.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment