Advertisement
Guest User

Untitled

a guest
Apr 18th, 2015
196
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.43 KB | None | 0 0
  1. choice = ['g','c','p']
  2.  
  3. my = process.argv[2]
  4. enemy = (->
  5. choice[Math.floor(Math.random() * choice.length)]
  6. )()
  7.  
  8. console.log "my: #{my}"
  9. console.log "enemy: #{enemy}"
  10.  
  11. judge = (my,enemy) ->
  12. table = {g: "c" ,c: "p",p: "g"}
  13. if my in choice and enemy in choice
  14. switch enemy
  15. when table[my] then return "Win"
  16. when my then return "Draw"
  17. else
  18. return "Lose"
  19. else
  20. return "error"
  21.  
  22. console.log judge(my,enemy)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement