Skip to content

Commit 6508554

Browse files
authored
Update script.js
1 parent a7db4af commit 6508554

File tree

1 file changed

+83
-83
lines changed

1 file changed

+83
-83
lines changed

color-guessor/script.js

Lines changed: 83 additions & 83 deletions
Original file line numberDiff line numberDiff line change
@@ -1,113 +1,113 @@
1-
var boxes=document.querySelectorAll(".box");
2-
var s=document.querySelector("#rgbspan");
3-
var colors=generateRandomColor(6);
4-
var pickedColor=colors[Math.floor(Math.random()*6)];
5-
s.textContent=pickedColor;
6-
var playbtn=document.querySelector("#playAgain");
7-
var easybtn=document.querySelector("#easyBtn");
8-
var hardbtn=document.querySelector("#hardBtn");
9-
var boxCount=6;
10-
var statusText=document.querySelector(".status");
11-
statusText.textContent="Lets Play!";
12-
13-
easybtn.addEventListener("click",function(){
14-
document.querySelector("h1").style.background="#f88989";
15-
statusText.textContent="Lets Play!";
16-
boxCount=3;
17-
this.style.background="#f88989";
18-
this.style.color="white";
19-
hardbtn.style.background="white";
20-
hardbtn.style.color="rgb(233,119,119)";
21-
22-
colors=generateRandomColor(boxCount);
23-
pickedColor=colors[Math.floor(Math.random()*3)];
24-
s.textContent=pickedColor;
25-
26-
for(var i=0;i<boxes.length;i++){
27-
if(colors[i]){
28-
boxes[i].style.background=colors[i];
29-
}else{
30-
boxes[i].style.display="none";
1+
var boxes = document.querySelectorAll(".box");
2+
var s = document.querySelector("#rgbspan");
3+
var colors = generateRandomColor(6);
4+
var pickedColor = colors[Math.floor(Math.random() * 6)];
5+
s.textContent = pickedColor;
6+
var playbtn = document.querySelector("#playAgain");
7+
var easybtn = document.querySelector("#easyBtn");
8+
var hardbtn = document.querySelector("#hardBtn");
9+
var boxCount = 6;
10+
var statusText = document.querySelector(".status");
11+
statusText.textContent = "Lets Play!";
12+
13+
easybtn.addEventListener("click", function() {
14+
document.querySelector("h1").style.background = "#f88989";
15+
statusText.textContent = "Lets Play!";
16+
boxCount = 3;
17+
this.style.background = "#f88989";
18+
this.style.color = "white";
19+
hardbtn.style.background = "white";
20+
hardbtn.style.color = "rgb(233,119,119)";
21+
22+
colors = generateRandomColor(boxCount);
23+
pickedColor = colors[Math.floor(Math.random() * 3)];
24+
s.textContent = pickedColor;
25+
26+
for (var i = 0; i < boxes.length; i++) {
27+
if (colors[i]) {
28+
boxes[i].style.background = colors[i];
29+
} else {
30+
boxes[i].style.display = "none";
3131
}
3232
}
3333

3434
});
35-
hardbtn.addEventListener("click",function(){
36-
document.querySelector("h1").style.background="rgb(233,119,119)";
37-
statusText.textContent="Lets Play!";
38-
39-
this.style.background="rgb(233,119,119)";
40-
this.style.color="white";
41-
easybtn.style.background="white";
42-
easybtn.style.color="rgb(233,119,119)";
43-
boxCount=6;
44-
45-
colors=generateRandomColor(boxCount);
46-
pickedColor=colors[Math.floor(Math.random()*6)];
47-
48-
for(var i=0;i<boxes.length;i++){
49-
boxes[i].style.background=colors[i];
50-
boxes[i].style.display="block";
51-
35+
hardbtn.addEventListener("click", function() {
36+
document.querySelector("h1").style.background = "rgb(233,119,119)";
37+
statusText.textContent = "Lets Play!";
38+
39+
this.style.background = "rgb(233,119,119)";
40+
this.style.color = "white";
41+
easybtn.style.background = "white";
42+
easybtn.style.color = "rgb(233,119,119)";
43+
boxCount = 6;
44+
45+
colors = generateRandomColor(boxCount);
46+
pickedColor = colors[Math.floor(Math.random() * 6)];
47+
48+
for (var i = 0; i < boxes.length; i++) {
49+
boxes[i].style.background = colors[i];
50+
boxes[i].style.display = "block";
51+
5252
}
5353

5454

5555
});
5656

5757

58-
playbtn.addEventListener("click",function(){
59-
document.querySelector("h1").style.background="rgb(233,119,119)";
60-
statusText.textContent="Lets Play!";
61-
58+
playbtn.addEventListener("click", function() {
59+
document.querySelector("h1").style.background = "rgb(233,119,119)";
60+
statusText.textContent = "Lets Play!";
61+
62+
63+
colors = generateRandomColor(boxCount);
64+
pickedColor = colors[Math.floor(Math.random() * boxCount)];
65+
s.textContent = pickedColor;
66+
67+
for (var i = 0; i < boxes.length; i++) {
68+
69+
boxes[i].style.background = colors[i];
6270

63-
colors=generateRandomColor(boxCount);
64-
pickedColor=colors[Math.floor(Math.random()*boxCount)];
65-
s.textContent=pickedColor;
6671

67-
for(var i=0;i<boxes.length;i++){
68-
69-
boxes[i].style.background=colors[i];
70-
71-
7272
}
7373
});
74-
for(var i=0;i<colors.length;i++){
75-
boxes[i].style.background=colors[i];
76-
boxes[i].addEventListener("click",function(){
77-
var selectedcolor=this.style.background;
78-
if(selectedcolor===pickedColor){
74+
for (var i = 0; i < colors.length; i++) {
75+
boxes[i].style.background = colors[i];
76+
boxes[i].addEventListener("click", function() {
77+
var selectedcolor = this.style.background;
78+
if (selectedcolor === pickedColor) {
7979
win();
80-
}
81-
else{
80+
} else {
8281
loose(this);
8382
}
8483
});
8584
}
8685

87-
function win(){
88-
for(var i=0;i<colors.length;i++){
89-
boxes[i].style.background=pickedColor;
86+
function win() {
87+
for (var i = 0; i < colors.length; i++) {
88+
boxes[i].style.background = pickedColor;
9089
}
91-
document.querySelector("h1").style.background=pickedColor;
92-
statusText.textContent="CORRECT!!!";
90+
document.querySelector("h1").style.background = pickedColor;
91+
statusText.textContent = "CORRECT!!!";
9392
}
9493

95-
function loose(a){
96-
a.style.background="#2f2f2f";
97-
statusText.textContent="TRY AGAIN !";
94+
function loose(a) {
95+
a.style.background = "#2f2f2f";
96+
statusText.textContent = "TRY AGAIN !";
9897
}
9998

100-
function generateRandomColor(num){
101-
var arr=[];
102-
for(var i=0;i<num;i++){
99+
function generateRandomColor(num) {
100+
var arr = [];
101+
for (var i = 0; i < num; i++) {
103102
arr.push(randomColor());
104103
}
105104
return arr;
106105
}
107106

108-
function randomColor(){
109-
var r=Math.floor(Math.random()*256);
110-
var g=Math.floor(Math.random()*256);
111-
var b=Math.floor(Math.random()*256);
112-
return "rgb("+ r + ", " + g + ", " + b + ")";
113-
}
107+
function randomColor() {
108+
var r = Math.floor(Math.random() * 256);
109+
var g = Math.floor(Math.random() * 256);
110+
var b = Math.floor(Math.random() * 256);
111+
return "rgb(" + r + ", " + g + ", " + b + ")";
112+
}
113+

0 commit comments

Comments
 (0)