Advertisement
Guest User

Guess the Number

a guest
Mar 6th, 2015
219
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
HTML 1.76 KB | None | 0 0
  1. <!DOCTYPE html>
  2.  
  3. <html>
  4. <head>
  5.     <title>Guess!</title>
  6.     <style type="text/css">
  7.         body {
  8.             text-align: center;font-family: Helvetica, Arial, sans-serif;
  9.             color: #2a2a2a;
  10.         }
  11.        
  12.         #result {
  13.             font-weight: 100;
  14.         }
  15.        
  16.         #correct {
  17.             font-weight: bold;
  18.             color: green;
  19.             font-style: italic;
  20.         }
  21.        
  22.         #inco{
  23.             font-weight: bold;
  24.             color: red;
  25.             font-style: italic;
  26.         }
  27.        
  28.         h3 {
  29.             margin-top: 50px;
  30.         }
  31.        
  32.         button {
  33.             margin-top: 10px;
  34.         }
  35.     </style>
  36. </head>
  37.  
  38. <body>
  39.  
  40.     <h3>How many fingers is the computer holding up?</h3>
  41.     <input id="guess" /><br />
  42.     <button id="go" onclick="guess();">Guess!</button><br /><br />
  43.     <h4 id="result"></h4>
  44.    
  45.     <script type="application/x-javascript">
  46.         function guess() {
  47.         var x=Math.random();
  48.         x=6*x;
  49.         x=Math.floor(x);
  50.         var guess=document.getElementById("guess");
  51.         var result=document.getElementById("result");
  52.        
  53.         if (guess.value=="") {
  54.             result.innerHTML="Please input your guess.";
  55.         } else if (x==guess.value) {
  56.             result.innerHTML="<span id='correct'>Correct!</span><br />The answer was " + x;
  57.             guess.value="";
  58.         } else if (guess.value > 5) {
  59.             result.innerHTML="Guess a number that is 5 or lower.";
  60.             guess.value="";
  61.         } else {
  62.             result.innerHTML="<span id='inco'>Incorrect.</span><br />You guessed " + guess.value + " but the answer was " + x;
  63.             guess.value="";
  64.         }
  65.         };
  66.     </script>
  67.  
  68. </body>
  69. </html>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement