This week only. Pastebin PRO Accounts Christmas Special! Don't miss out!Want more features on Pastebin? Sign Up, it's FREE!
Guest

Rock paper scissors game - codeacademy

By: a guest on Dec 9th, 2012  |  syntax: JavaScript  |  size: 0.93 KB  |  views: 3,348  |  expires: Never
download  |  raw  |  embed  |  report abuse  |  print
Text below is selected. Please press Ctrl+C to copy to your clipboard. (⌘+C on Mac)
  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.  
  11. var compare = function(choice1, choice2) {
  12.         if (choice1 === choice2) {
  13.                 return("The result is a tie!");
  14.         }
  15.        
  16.         if (choice1 === "rock") {
  17.                 if (choice2 === "scissors") {
  18.                         return("Rock wins.");
  19.                 } else {
  20.                         return("Paper wins.");
  21.                 }
  22.         }
  23.        
  24.         if (choice1 === "paper") {
  25.                 if (choice2 === "rock") {
  26.                         return("paper winds.");
  27.                 } else {
  28.                         return ("Scissors win");
  29.                 }
  30.         }
  31.        
  32.         if (choice1 === "scissors") {
  33.                 if (choice2 === "paper") {
  34.                         return("Scissors win.");
  35.                 } else {
  36.                         return ("rock wins");
  37.                 }
  38.         }
  39.        
  40. };
  41.  
  42. console.log("You chose" + " " + userChoice + ".");
  43. console.log("Computer chose" + " " + computerChoice + ".");
  44. compare(userChoice, computerChoice);
clone this paste RAW Paste Data