forked from omkrishna/ColorGame
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathIndex1.html
166 lines (151 loc) · 5.44 KB
/
Index1.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
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
<!DOCTYPE html>
<html>
<head>
<title>Color Game</title>
<link rel="stylesheet" href="./index1.css" />
</head>
<body onload="newGame()" style="background-color:black;">
<div id="header">
<h2>The Great</h2>
<h1 id="header-clue">superman</h1>
<h2>Guessing Game</h2>
</div>
<div id="container1">
<div class="tile" id="1"></div>
<div class="tile" id="2"></div>
<div class="tile" id="3"></div>
</div>
<br>
<div id="container2">
<div class="tile" id="4"></div>
<div class="tile" id="5"></div>
<div class="tile" id="6"></div>
</div>
<div id="container3">
<h1 id="7">Numberoftries(x)</h1>
</div>
<h2 onclick="newGame()" style="background-color:darkmagenta; text-align:center;">Click to start new game</h2>
<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 y=0;
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();
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);
document.getElementById("header-clue").innerHTML = correctColor;
y=0;
document.getElementById("7").innerHTML = "Number of tries:".concat(y);
}
function tries() {
y=y+1;
// console.log(y);
document.getElementById("7").innerHTML = "Number of tries:".concat(y);
}
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;
} else {
t1.style.background = "black";
tries();
}
});
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("header").style.background = correctColor;
} else {
t2.style.background = "black";
tries();
}
});
t3.addEventListener("click", function () {
if (t3.style.background == correctColor) {
t2.style.background = correctColor;
t1.style.background = correctColor;
t4.style.background = correctColor;
t5.style.background = correctColor;
t6.style.background = correctColor;
document.getElementById("header").style.background = correctColor;
} else {
t3.style.background = "black";
tries();
}
});
t4.addEventListener("click", function () {
if (t4.style.background == correctColor) {
t2.style.background = correctColor;
t3.style.background = correctColor;
t1.style.background = correctColor;
t5.style.background = correctColor;
t6.style.background = correctColor;
document.getElementById("header").style.background = correctColor;
} else {
t4.style.background = "black";
tries();
}
});
t5.addEventListener("click", function () {
if (t5.style.background == correctColor) {
t2.style.background = correctColor;
t3.style.background = correctColor;
t4.style.background = correctColor;
t1.style.background = correctColor;
t6.style.background = correctColor;
document.getElementById("header").style.background = correctColor;
} else {
t5.style.background = "black";
tries();
}
});
t6.addEventListener("click", function () {
if (t6.style.background == correctColor) {
t2.style.background = correctColor;
t3.style.background = correctColor;
t4.style.background = correctColor;
t5.style.background = correctColor;
t1.style.background = correctColor;
document.getElementById("header").style.background = correctColor;
} else {
t6.style.background = "black";
tries();
}
});
</script>
</body>
</html>