Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <!DOCTYPE html>
- <html>
- <head>
- <title>GuessNumber</title>
- <script>
- var correct = Math.ceil(Math.random() * 10)
- var attemps = 0
- function validate(){
- var t = parseInt(document.getElementById("textinput").value, 10)
- if (correct == t){
- alert("You guessed the right number in "+attemps+" attemps")
- return true
- } else if (t > correct){
- alert("Try lower")
- } else if (t < correct){
- alert("Try higher")
- } else {
- alert("Invalid input")
- }
- attemps++
- return false
- }
- </script>
- <style>
- input[type=submit]{
- border: solid;
- margin-top: 14px;
- margin-left: 60px;
- width: 50px;
- height: 30;
- }
- #textinput{
- border: solid;
- height: 30px;
- width: 180px;
- }
- body{
- position: absolute;
- right: 30%;
- top: 30%;
- background-color: red;
- }
- </style>
- </head>
- <body>
- <h2>Guess the number between 0 and 100</h2>
- <form onsubmit="return validate()">
- <input type="number" id="textinput" placeholder="Enter a number" required />
- <br /><input type="submit" />
- </form>
- </body>
- </html>
Advertisement
Add Comment
Please, Sign In to add comment