-
Notifications
You must be signed in to change notification settings - Fork 0
/
game.html
84 lines (78 loc) · 2.18 KB
/
game.html
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
<!DOCTYPE html>
<!-- This code contains a form with a number input and a submit button. When the user enters his number and presses the submit button, a message is displayed according to the relationship of the user's guess with my number and the user must continue searching for my number. -->
<html>
<head>
<title>Guess the Number</title>
<meta charset="utf-8">
<style type="text/css">
body {
font-family: Arial, Helvetica, sans-serif;
background-color: #f4f4f4;
}
h1 {
margin-top: 50px;
text-align: center;
color: #333;
}
form {
display: flex;
flex-direction: column;
align-items: center;
margin-top: 30px;
}
input[type="number"] {
padding: 10px;
border: none;
border-radius: 5px;
margin-bottom: 10px;
width: 200px;
text-align: center;
font-size: 16px;
}
input[type="submit"] {
background-color: #333;
color: #fff;
border: none;
border-radius: 5px;
padding: 10px 20px;
cursor: pointer;
font-size: 16px;
margin-top: 10px;
}
input[type="submit"]:hover {
background-color: #555;
}
</style>
</head>
<body>
<h1>Guess the Number</h1>
<form id="guess-form">
<label for="number">Enter your guess:</label>
<input type="number" id="number" name="number" required>
<input type="submit" value="Submit">
</form>
<script type="text/javascript">
// Generate a random number between 1 and 100
var randomNumber = Math.floor(Math.random() * 100) + 1;
// Get form element from the DOM
var guessForm = document.getElementById('guess-form');
// Add event listener to the form on submit
guessForm.addEventListener('submit', function(event) {
event.preventDefault();
// Get the user's guess from the input field
var userGuess = parseInt(document.getElementById('number').value);
// Check if the user's guess is correct, too high or too low
if (userGuess === randomNumber) {
alert('Congratulations! You guessed the number!');
} else if (userGuess < randomNumber) {
alert('Your guess is too low. Try again.');
} else {
alert('Your guess is too high. Try again.');
}
});
</script>
<div class="me">
<a target="_blank" href="https://alireza.pro">My Website</a>
</div>
</body>
</html>