-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathnumguess.html
More file actions
79 lines (76 loc) · 2.64 KB
/
numguess.html
File metadata and controls
79 lines (76 loc) · 2.64 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
66
67
68
69
70
71
72
73
74
75
76
77
78
79
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8" />
<title>Fakemon's Website | Number Guesser</title>
<script>
function random(min, max) {
return Math.floor(Math.random() * (max - min)) + min;
}
let rng = random(0,100)
let guess;
let status;
let tries = 0;
let hasSucceeded = false
document.addEventListener("DOMContentLoaded", () => {
guess = document.getElementById("guess");
status = document.getElementById("status");
})
function submitguess() {
if (!hasSucceeded)
{tries++
if (Number(guess.value) === rng) {
status.innerHTML = `Congrats! You got it correct in ${tries} ${(tries == 1)? "try! I don't think even <i>I</i> could do that without cheating" : "tries"}!` // Pluralization
hasSucceeded = true
} else {
if (rng > Number(guess.value)) {
status.innerHTML = "Womp womp! You got it wrong! Guess again! (Maybe try making your answer a little <b>higher</b>?)"
} else {
status.innerHTML = "Womp womp! You got it wrong! Guess again! (Maybe try making your answer a little <b>lower</b>?)"
}}
} else {
status.innerHTML = "<i>You already got it right...</i>"
}
}
function validifyValue() {
guess.value = clamp(guess.value, 0, 100)
}
function clamp(value, min, max) {
if (value > max) {
return max
} else if (value < min) {
return min
} else {
return value
}
}
document.onkeydown = (key) => {
if (key.key === "Enter") {
submitguess()
}
};
</script>
<script src="UniversalElements.js">// Script for automatically filling element data across pages (this is an anti-React household)</script>
</head>
<body>
<div class="main">
<div class="navbar">
<!--chatgpt, give me a navbar // what do you mean its not chatgpt? // woah, it's my own stupid code? // universalelements.js is doing all this cool work???? // my mental state is potato?????????-->
</div>
<img
src="https://uploads.scratch.mit.edu/get_image/user/117698316_99x99.png"
class="pfp"
/>
<h1>Number Guesser</h1>
<i>Guess a random number between 0 and 100!</i>
<br>
<h3 id="status"></h3>
<input id="guess" type="number" placeholder="Put your guess here!" onchange="validifyValue()"></input>
<button id="submit" onclick="submitguess()">Submit!</button>
<hr class="but" />
<div class="links">
<!--insert smthn funny abt universalelements.js or whatever-->
</div>
</div>
</body>
</html>