Last active
August 29, 2015 14:07
-
-
Save RShergold/34989e0301b84a906797 to your computer and use it in GitHub Desktop.
rock paper scissors javascript - code golf - small as possible
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
var moves = ['rock','paper','scissors'], | |
results = ['we draw','you loose','you win'], | |
user_move = moves.indexOf(prompt(moves+'?')), | |
computer_move, | |
result; | |
while (user_move > -1) { | |
computer_move = Math.round(Math.random()*2); | |
result = results[ (2*user_move+computer_move)%3 ]; | |
alert( 'You choose: ' +moves[user_move]+ '\nI chose:' +moves[computer_move]+ '\n' +result); | |
user_move = moves.indexOf(prompt(moves+'?',moves[user_move])); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
or even smaller in ruby!