-
-
Save clavery/6370251 to your computer and use it in GitHub Desktop.
This file contains 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
// 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"); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
I really like the modulo.