Advertisement
Guest User

Untitled

a guest
Jun 25th, 2013
93
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. if (computerChoice < 0.34) {
  4.     computerChoice = "rock";
  5. } else if(computerChoice <= 0.67) {
  6.     computerChoice = "paper";
  7. } else {
  8.     computerChoice = "scissors";
  9. }
  10. var compare=function(choice1, choice2) {
  11.     if (choice1===choice2)
  12.        return "The result is a tie!";
  13.        
  14.    
  15.     if(choice1 === "rock")
  16.        {
  17.            if (choice2 === "scissors")
  18.            {
  19.                return "rock wins.";
  20.            }
  21.               else if (choice2 === "paper")
  22.               {
  23.                   return "paper wins.";
  24.               }
  25.         }
  26.    
  27.     else if(choice1 === "paper")
  28.         {
  29.             if (choice2 === "rock")
  30.             {
  31.                 return "paper wins!";
  32.             }
  33.               else if (choice2 === "scissors")
  34.               {
  35.                   return "scissors wins.";
  36.               }
  37.         }
  38.     else if (choice1 === "scissors")
  39.         {
  40.             if (choice2 === "rock")
  41.             {
  42.                 return "rock wins!";
  43.             }
  44.               else if (choice2 === "paper")
  45.               {
  46.                   return "scissors wins!";
  47.               }
  48.         }
  49.        
  50.    
  51. };
  52. console.log(compare (choice1, choice2));
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement