ForeverDev

Untitled

Oct 4th, 2014
243
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. var moves = {1 : "rock", 2 : "paper", 3 : "scissors"}
  2.  
  3. function rand(maximum) {
  4.     return moves[Math.ceil(Math.random() * maximum)]
  5. }
  6.  
  7. while (true) {
  8.     var enemyDecision = rand(3);
  9.     var myDecision = prompt("Rock, paper, or scissors?").toLowerCase()
  10.     console.log(
  11.         myDecision == enemyDecision && "Tie!  You both chose " + myDecision ||
  12.         (
  13.             myDecision == "rock" && enemyDecision == "paper" ||
  14.             myDecision == "paper" && enemyDecision == "scissors" ||
  15.             myDecision == "scissors" && enemyDecision == "rock"
  16.         ) && "You lose! Opponent chose " + enemyDecision + " and you chose " + myDecision ||
  17.         "You win! Opponent chose " + enemyDecision + " and you chose " + myDecision
  18.     )
  19. }
Advertisement
Add Comment
Please, Sign In to add comment