-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathGuessing Game
More file actions
46 lines (38 loc) · 1.16 KB
/
Guessing Game
File metadata and controls
46 lines (38 loc) · 1.16 KB
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
<!DOCTYPE html>
<html>
<head>
<title>Guessing Game</title>
<style>
body {
font-family: Arial, sans-serif;
}
</style>
</head>
<body>
<h1>Guessing Game</h1>
<p>Enter a number:</p>
<input id="user-input" type="number">
<button id="submit-btn">Submit</button>
<div id="feedback"></div>
<script>
const targetNumber = Math.floor(Math.random() * 100) + 1;
const userInputField = document.getElementById("user-input");
const submitButton = document.getElementById("submit-btn");
const feedbackDiv = document.getElementById("feedback");
submitButton.addEventListener("click", () => {
const userInput = parseInt(userInputField.value);
if (isNaN(userInput)) {
feedbackDiv.innerText = "Please enter a valid number!";
} else {
if (userInput > targetNumber) {
feedbackDiv.innerText = "little high! Try again.";
} else if (userInput < targetNumber) {
feedbackDiv.innerText = "little low! Try again.";
} else {
feedbackDiv.innerText = " Congratulations! You guessed the correct number!";
}
}
});
</script>
</body>
</html>