-
Notifications
You must be signed in to change notification settings - Fork 83
/
index.html
67 lines (58 loc) · 1.8 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
<!DOCTYPE html>
<html>
<head>
<title>Color Game</title>
<link rel="stylesheet" href="./index.css" />
</head>
<body onload="newGame()">
<div id="header">
<h2>The Great</h2>
<h1 id="header-clue">rgb(xxx,xxx,xxx)</h1>
<h2>Guessing Game</h2>
</div>
<div id="container">
<div class="tile" id="1"></div>
<div class="tile" id="2"></div>
</div>
<script>
var t1 = document.getElementById("1");
var t2 = document.getElementById("2");
var x;
var correctColor;
function getRandomColor() {
var letters = "0123456789ABCDEF";
var color = "#";
for (var i = 0; i < 6; i++) {
color += letters[Math.floor(Math.random() * 16)];
}
return color;
}
function newGame() {
t1.style.background = getRandomColor();
t2.style.background = getRandomColor();
x = Math.floor(Math.random() * 2 + 1);
if (x == 1) correctColor = t1.style.background;
else correctColor = t2.style.background;
/* console.log(x);
console.log(correctColor); */
document.getElementById("header-clue").innerHTML = correctColor;
}
t1.addEventListener("click", function () {
if (t1.style.background == correctColor) {
t2.style.background = correctColor;
document.getElementById("header").style.background = correctColor;
} else {
t1.style.background = "black";
}
});
t2.addEventListener("click", function () {
if (t2.style.background == correctColor) {
t1.style.background = correctColor;
document.getElementById("header").style.background = correctColor;
} else {
t2.style.background = "black";
}
});
</script>
</body>
</html>