Advertisement
Guest User

Untitled

a guest
May 26th, 2016
65
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. } console.log("Computer: " + computerChoice);
  10.  
  11.  
  12. var compare = function(choice1,choice2)
  13. {
  14.     if(choice1 == choice2)
  15.     {
  16.         return "The result is a tie!";
  17.     }
  18.     else if (choice1 == "Rock")
  19.     {
  20.         if(choice2 == "Scissors")
  21.         {
  22.             return "Rock wins";
  23.         }
  24.         else
  25.         {
  26.             return "Paper wins";
  27.         }
  28.     }
  29.     else if (choice1 == "Paper")
  30.     {
  31.         if(choice2 == "Rock")
  32.         {
  33.             return "Paper wins";
  34.         }
  35.         else
  36.         {
  37.             return "Scissors wins";
  38.         }
  39.     }
  40.     else if (choice1 == "Scissors")
  41.     {
  42.         if(choice2 == "Paper")
  43.         {
  44.             return "Scissors wins";
  45.         }
  46.         else
  47.         {
  48.             return "Rock wins";
  49.         }
  50.     }
  51.     {
  52.         if(choice1, choice2 ==! "Paper", "Rock", "Scissors")
  53.         {
  54.            var userChoice2 = prompt("Case sensitive answer required - remember to choose Rock, Paper or Scissors. Try again!");
  55.         }
  56.     }  
  57. }
  58.  
  59. console.log("User Choice: " + userChoice);
  60. console.log("Computer Choice: " + computerChoice);
  61. prompt(compare(userChoice, userChoice2, computerChoice));
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement