-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.html
101 lines (79 loc) · 2.88 KB
/
index.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
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<title> The # Guessing Game </title>
<style>
html {
font-family: sans-serif;
}
body {
/* width: 50%;
max-width: 800px;
min-width: 480px;
margin: 0 auto; */
position: absolute;
top: 50%;
left: 50%;
transform: translate(-50%, -50%);
background-color: rgb(252, 255, 224);
}
.textbgc {
color: rgb(5, 0, 0);
padding: 3px;
}
</style>
</head>
<body>
<h1> GUESS THE NUMBER :D </h1>
<p> We chose a number between 1 - 10. Can you guess it? </p>
<div>
<label> Enter a guess: </label>
<input type = "text" id = "guessField" class = "guessField">
<input type = "submit" value = " ENTER " class = "guessSubmit" id = "submitGuess">
<p class="textbgc"></p>
</div>
<script>
const textbgc = document.querySelector('.textbgc');
const arr = ["crimson", "DarkRed", "FireBrick", "IndianRed", "Red", "Tomato"];
var rand = Math.floor(Math.random() * 10 + 1);
var guesses = 1;
document.getElementById("submitGuess").onclick = function() {
var userInput = document.getElementById("guessField").value;
if (userInput == rand) {
// html.backgroundColor = "blue";
textbgc.textContent = 'NOO, YOU GUESSED IT. IT TOOK YOU ' + guesses + ' TRIES!!!!!!!';
textbgc.style.backgroundColor = 'honeydew';
document.body.style.backgroundColor = "chartreuse";
}
else if (userInput > rand) {
guesses++;
textbgc.textContent = 'HA NOPE! TRY AGAIN (... maybe a smaller # this time)';
textbgc.style.backgroundColor = 'red';
// document.body.style.backgroundColor = "crimson";
for (let i = 0; i < arr.length(); i++) {
var changeColor = arr[i];
}
document.body.style.backgroundColor = changeColor;
}
else {
guesses++;
textbgc.textContent = 'HA NOPE! TRY AGAIN (... maybe a greater # this time)'
textbgc.style.backgroundColor = 'red';
for (let i = 0; i < arr.length(); i++) {
var changeColor = arr[i];
}
document.body.style.backgroundColor = changeColor;
}
}
/*
let inputElement = document.querySelector("#guessField");
inputElement.addEventListener("keyup", function(event) {
if (event.key == "Enter") {
submitGuess();
}
});
*/
</script>
</body>
</html>