-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathguessnumber.html
More file actions
65 lines (47 loc) · 1.44 KB
/
guessnumber.html
File metadata and controls
65 lines (47 loc) · 1.44 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
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Guess The Number</title>
<style>
</style>
</head>
<body>
<script>
let answer;
let attempts = 0
let guess;
let running = true;
min = 50;
max = 100;
answer = Math.floor(Math.random() * (max - min)) + min;
console.log(answer)
while (running) {
guess = window.prompt(`Enter Your Answer: ${min} - ${max}`);
guess = Number(guess);
if (isNaN(guess)) {
attempts++
window.alert("Please Enter A Valid Number")
}
else if (guess < min && guess > max) {
attempts++
window.alert("Please Enter A Valid Number")
}
else {
attempts++
if (guess < answer) {
window.alert("Your Guess is Lower, TRY AGAIN")
}
else if (guess > answer) {
window.alert("Your Guess is Higher, TRY AGAIN")
}
else {
window.alert(`Correct YOU WON NOTHING! and took ${attempts} guess!`)
running = false;
}
}
}
</script>
</body>
</html>