forked from omkrishna/ColorGame
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathindex.html
More file actions
196 lines (164 loc) · 6.78 KB
/
index.html
File metadata and controls
196 lines (164 loc) · 6.78 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
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
<!DOCTYPE html>
<html>
<head>
<title>Color Game</title>
<link rel="stylesheet" href="./index.css" />
</head>
<body onload="newGame()">
<div id = "button">
<button class = "button" onclick="newGame()" >New Game</button>
</div>
<div id="header">
<h2>The Great</h2>
<h1 id="header-clue">rgb(xxx,xxx,xxx)</h1>
<h2>Guessing Game</h2>
</div>
<div id = "counter"> </div>
<div class="grid-container" id="container">
<div class="tile" id="1"></div>
<div class="tile" id="2"></div>
<div class = "tile" id = "3"></div>
<div class = "tile" id = "4"></div>
<div class = "tile" id = "5"></div>
<div class = "tile" id = "6"></div>
</div>
<script>
var t1 = document.getElementById("1");
var t2 = document.getElementById("2");
var t3 = document.getElementById("3");
var t4 = document.getElementById("4");
var t5 = document.getElementById("5");
var t6 = document.getElementById("6");
var x;
var correctColor;
var count;
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();
t3.style.background = getRandomColor();
t4.style.background = getRandomColor();
t5.style.background = getRandomColor();
t6.style.background = getRandomColor();
x = Math.floor(Math.random() * 6 + 1);
if (x == 1) correctColor = t1.style.background;
else if (x==2) correctColor = t2.style.background;
else if (x==3) correctColor = t3.style.background;
else if (x==4) correctColor = t4.style.background;
else if (x==5) correctColor = t5.style.background;
else correctColor = t6.style.background;
/* console.log(x);
console.log(correctColor); */
count = 0
document.getElementById("header-clue").innerHTML = correctColor;
document.getElementById("counter").innerHTML = "Numnber of Tries : x".replace("x",count);
}
t1.addEventListener("click", function () {
if (t1.style.background == correctColor) {
t2.style.background = correctColor;
t3.style.background = correctColor;
t4.style.background = correctColor;
t5.style.background = correctColor;
t6.style.background = correctColor;
document.getElementById("header").style.background = correctColor;
document.getElementById("counter").style.background = correctColor;
document.getElementById("button").style.background = correctColor;
} else {
t1.style.background = "black";
count++;
document.getElementById("counter").innerHTML = "Numnber of Tries : x".replace("x",count);
}
});
t2.addEventListener("click", function () {
if (t2.style.background == correctColor) {
t1.style.background = correctColor;
t3.style.background = correctColor;
t4.style.background = correctColor;
t5.style.background = correctColor;
t6.style.background = correctColor;
document.getElementById("counter").style.background = correctColor;
document.getElementById("button").style.background = correctColor;
document.getElementById("header").style.background = correctColor;
} else {
t2.style.background = "black";
count++;
document.getElementById("counter").innerHTML = "Numnber of Tries : x".replace("x",count);
}
});
t3.addEventListener("click",function(){
if (t3.style.background==correctColor){
t1.style.background = correctColor;
t2.style.background = correctColor;
t4.style.background = correctColor;
t5.style.background = correctColor;
t6.style.background = correctColor;
document.getElementById("counter").style.background = correctColor;
document.getElementById("button").style.background = correctColor;
document.getElementById("header").style.background = correctColor;
}else{
t3.style.background = "black";
count++;
document.getElementById("counter").innerHTML = "Numnber of Tries : x".replace("x",count);
}
});
t4.addEventListener("click",function(){
if (t4.style.background ==correctColor){
t1.style.background = correctColor;
t2.style.background = correctColor;
t3.style.background = correctColor;
t5.style.background = correctColor;
t6.style.background = correctColor;
document.getElementById("counter").style.background = correctColor;
document.getElementById("button").style.background = correctColor;
document.getElementById("header").style.background = correctColor;
}
else{
t4.style.background = "black";
count++;
document.getElementById("counter").innerHTML = "Numnber of Tries : x".replace("x",count);
}
});
t5.addEventListener("click",function(){
if (t5.style.background ==correctColor){
t1.style.background = correctColor;
t2.style.background = correctColor;
t3.style.background = correctColor;
t4.style.background = correctColor;
t6.style.background = correctColor;
document.getElementById("counter").style.background = correctColor;
document.getElementById("button").style.background = correctColor;
document.getElementById("header").style.background = correctColor;
}
else{
t5.style.background = "black";
count++;
document.getElementById("counter").innerHTML = "Numnber of Tries : x".replace("x",count);
}
});
t6.addEventListener("click",function(){
if (t6.style.background ==correctColor){
t1.style.background = correctColor;
t2.style.background = correctColor;
t3.style.background = correctColor;
t4.style.background = correctColor;
t5.style.background = correctColor;
document.getElementById("counter").style.background = correctColor;
document.getElementById("button").style.background = correctColor;
document.getElementById("header").style.background = correctColor;
}
else{
t6.style.background = "black";
count++;
document.getElementById("counter").innerHTML = "Numnber of Tries : x".replace("x",count);
}
});
</script>
</body>
</html>