Skip to content

Instantly share code, notes, and snippets.

@qb20nh
Created December 7, 2021 13:19
Show Gist options
  • Save qb20nh/2b58cc648b412e486d8486dfaa512525 to your computer and use it in GitHub Desktop.
Save qb20nh/2b58cc648b412e486d8486dfaa512525 to your computer and use it in GitHub Desktop.
RPS.js
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])
@qb20nh
Copy link
Author

qb20nh commented Dec 7, 2021

Bad code, don't try this at home

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