Advertisement
Guest User

Untitled

a guest
Mar 22nd, 2017
72
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. <html>
  2. <head>
  3.     <title>ROCK PAPER SCISSORS THE GAME</title>
  4. </head>
  5. <body>
  6.  
  7.     <button onClick='choose("rock")'>Rock</button>
  8.     <button onClick='choose("paper")'>Paper</button>
  9.     <button onClick='choose("scissors")'>Scissors</button><br>
  10.     <button onClick='compare(userschoice, computerschoice)'>Go!</button>
  11.     <p id="result"></p>
  12.    
  13.     <script>
  14.    
  15.     var userschoice;
  16.     var choose = function(choice)
  17.     {
  18.         userschoice = choice;
  19.     }
  20.    
  21.     var computerschoice = Math.random();
  22.    
  23.     if (0 < computerschoice < 0.30)
  24.     {
  25.         computerschoice = "rock";
  26.     }
  27.     else if (0.31 < computerschoice < 0.60)
  28.     {
  29.         computerschoice = "paper";
  30.     }
  31.     else
  32.     {
  33.         computerschoice = "scissors";
  34.     }
  35.     var compare = function(firstChoice,secondChoice)
  36.     {
  37.         if (firstChoice === secondChoice)
  38.         {
  39.             document.getElementById("result").innerHTML = ("It's a tie!")
  40.         }
  41.         else if (firstChoice === "rock")
  42.         {
  43.             if (secondChoice === "scissors")
  44.             {
  45.                 document.getElementById("result").innerHTML = ("You win!")
  46.             }
  47.             else
  48.             {
  49.                 document.getElementById("result").innerHTML = ("You lost.")
  50.             }
  51.         }
  52.         else if (firstChoice === "paper")
  53.         {
  54.             if (secondChoice === "rock")
  55.             {
  56.                 document.getElementById("result").innerHTML = ("You win!")
  57.             }
  58.             else
  59.             {
  60.                 document.getElementById("result").innerHTML = ("You lost.")
  61.             }
  62.         }
  63.         else if (firstChoice === "scissors")
  64.         {
  65.             if (secondChoice === "paper")
  66.             {
  67.                 document.getElementById("result").innerHTML = ("You win!")
  68.             }
  69.             else
  70.             {
  71.                 document.getElementById("result").innerHTML = ("You lost.")
  72.             }
  73.         }
  74.     }
  75.     compare(userschoice, computerschoice)
  76.    
  77.     </script>
  78. </body>
  79. </html>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement