Advertisement
BullyATWiiplaza

Rock, Paper Scissors

Dec 6th, 2014
235
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. var userChoice = prompt("Do you choose rock, paper or scissors?");
  2. var computerChoice = Math.random();
  3.  
  4. if (computerChoice < 0.34)
  5. {
  6.     computerChoice = "rock";
  7. } else if (computerChoice <= 0.67)
  8. {
  9.     computerChoice = "paper";
  10. } else
  11. {
  12.     computerChoice = "scissors";
  13. }
  14.  
  15. console.log("Computer: " + computerChoice);
  16.  
  17. var compare = function(choice1, choice2)
  18. {
  19.     if(choice1 === choice2)
  20.     {
  21.         return "The result is a tie";
  22.     } else if (choice1 === "rock")
  23.     {
  24.         if (choice2 === "scissors")
  25.         {
  26.             return "rock wins";
  27.         } else
  28.         {
  29.             return "paper wins";
  30.         }
  31.     }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement