Created
December 7, 2021 13:19
-
-
Save qb20nh/2b58cc648b412e486d8486dfaa512525 to your computer and use it in GitHub Desktop.
RPS.js
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
let com = Math.random()*3 | 0 | |
let usr | |
const rps = 'rock paper scissors'.split(' ') | |
const score = 'draw win lose'.split(' ') | |
let usrNum | |
while ((usrNum = rps.indexOf(usr = prompt('choose your move'))) === -1) { | |
alert('invalid move') | |
} | |
alert('you chose ' + usr) | |
alert('computer chose ' + rps[com]) | |
let result = (usrNum - com + 3) % 3 | |
alert((result ? 'you ' : '') + score[result]) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Bad code, don't try this at home