Theeaxe

Game: Rock, Paper, Scissors

Mar 4th, 2014
109
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 1.38 KB | None | 0 0
  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. console.log("Your choice: " + userChoice);
  12. choice1 = userChoice;
  13. choice2 = computerChoice;
  14.  
  15. var compare = function(choice1, choice2) {
  16.     if (choice1 === choice2) {
  17.         return "The result is a tie!";
  18.     } else if (choice1 === "rock") {
  19.         if (choice2 === "scissors") {
  20.             return "rock wins";
  21.         }
  22.         else {
  23.             return "paper wins";
  24.         }
  25.     } else if (choice1 === "paper") {
  26.         if (choice2 === "rock") {
  27.             return "paper wins"
  28.         }
  29.         else if (choice2 === "scissors") {
  30.             return "scissors win"
  31.         }
  32.         else {
  33.             return "The result is a tie!"
  34.         }
  35.     } else if (choice1 === "scissors") {
  36.         if (choice2 === "paper") {
  37.             return "scissors win"
  38.         }
  39.         else {
  40.             return "rock wins"
  41.         }
  42.     } else if (choice1 != "rock" || "paper" || "scissors") {
  43.         return "Invalid input, please try again later."
  44.     }
  45. }
  46. confirm("Your choice: " + userChoice + ". " + "Computer: " + computerChoice + ".  " + compare(choice1,choice2))
Advertisement
Add Comment
Please, Sign In to add comment