Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <!DOCTYPE html>
- <html>
- <head>
- <title>Guess!</title>
- <style type="text/css">
- body {
- text-align: center;font-family: Helvetica, Arial, sans-serif;
- color: #2a2a2a;
- }
- #result {
- font-weight: 100;
- }
- #correct {
- font-weight: bold;
- color: green;
- font-style: italic;
- }
- #inco{
- font-weight: bold;
- color: red;
- font-style: italic;
- }
- h3 {
- margin-top: 50px;
- }
- button {
- margin-top: 10px;
- }
- </style>
- </head>
- <body>
- <h3>How many fingers is the computer holding up?</h3>
- <input id="guess" /><br />
- <button id="go" onclick="guess();">Guess!</button><br /><br />
- <h4 id="result"></h4>
- <script type="application/x-javascript">
- function guess() {
- var x=Math.random();
- x=6*x;
- x=Math.floor(x);
- var guess=document.getElementById("guess");
- var result=document.getElementById("result");
- if (guess.value=="") {
- result.innerHTML="Please input your guess.";
- } else if (x==guess.value) {
- result.innerHTML="<span id='correct'>Correct!</span><br />The answer was " + x;
- guess.value="";
- } else if (guess.value > 5) {
- result.innerHTML="Guess a number that is 5 or lower.";
- guess.value="";
- } else {
- result.innerHTML="<span id='inco'>Incorrect.</span><br />You guessed " + guess.value + " but the answer was " + x;
- guess.value="";
- }
- };
- </script>
- </body>
- </html>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement