Advertisement
Guest User

Untitled

a guest
Sep 28th, 2016
54
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.33) {
  4.     computerChoice = "rock";
  5. } else if(computerChoice >= 0.66) {
  6.     computerChoice = "paper";
  7. } else {
  8.     computerChoice = "scissors";
  9. } console.log("Computer: " + computerChoice);
  10.  
  11. var compare = function(choice1, choice2) {
  12.     if(choice1 === choice2) {
  13.         return "The result is a tie!";
  14.     }
  15.     else if (choice1 === "rock") {
  16.        
  17.         if(choice2 === "scissors") {
  18.             return "rock wins";
  19.         }
  20.         else {
  21.             return "paper wins";
  22.         }
  23.     }
  24.     else if (choice1 === "paper") {
  25.         if (choice2 === "rock") {
  26.             return "paper wins";
  27.         }
  28.         else {
  29.             return "scissors wins";
  30.         }
  31.     }
  32.     else if(choice1 === "scissors") {
  33.         if (choice2 === "rock") {
  34.             return "rock wins";
  35.         }
  36.         else {
  37.             return "scissors wins";
  38.         }
  39.     }
  40. }
  41.  
  42. alert("The computer chooses " + computerChoice);
  43. (compare(userChoice,computerChoice));
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement