-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathgoogledoodle
83 lines (73 loc) · 2.21 KB
/
googledoodle
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
<!DOCTYPE html>
<html>
<head>
<title>Guess the Number</title>
<style>
body {
font-family: Arial, sans-serif;
text-align: center;
}
h1 {
color: #333;
}
.container {
margin-top: 100px;
}
.input-group {
margin-top: 20px;
}
.input-group input {
padding: 10px;
width: 200px;
font-size: 16px;
}
.input-group button {
padding: 10px 20px;
font-size: 16px;
background-color: #333;
color: #fff;
border: none;
cursor: pointer;
}
.result {
margin-top: 20px;
font-size: 18px;
}
</style>
</head>
<body>
<h1>Guess the Number</h1>
<div class="container">
<p>Guess a number between 1 and 100:</p>
<div class="input-group">
<input type="number" id="guessInput" min="1" max="100" required>
<button onclick="checkGuess()">Guess</button>
</div>
<p class="result" id="result"></p>
</div>
<script>
var randomNumber = Math.floor(Math.random() * 100) + 1;
var result = document.getElementById("result");
function checkGuess() {
var guessInput = document.getElementById("guessInput");
var guess = parseInt(guessInput.value);
if (isNaN(guess) || guess < 1 || guess > 100) {
result.textContent = "Please enter a valid number between 1 and 100.";
result.style.color = "red";
} else if (guess === randomNumber) {
result.textContent = "Congratulations! You guessed the correct number.";
result.style.color = "green";
guessInput.disabled = true;
} else if (guess < randomNumber) {
result.textContent = "Too low! Try again.";
result.style.color = "red";
} else {
result.textContent = "Too high! Try again.";
result.style.color = "red";
}
guessInput.value = "";
guessInput.focus();
}
</script>
</body>
</html>