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" ;
31
31
}
32
32
}
33
33
34
34
} ) ;
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
+
52
52
}
53
53
54
54
55
55
} ) ;
56
56
57
57
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 ] ;
62
70
63
- colors = generateRandomColor ( boxCount ) ;
64
- pickedColor = colors [ Math . floor ( Math . random ( ) * boxCount ) ] ;
65
- s . textContent = pickedColor ;
66
71
67
- for ( var i = 0 ; i < boxes . length ; i ++ ) {
68
-
69
- boxes [ i ] . style . background = colors [ i ] ;
70
-
71
-
72
72
}
73
73
} ) ;
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 ) {
79
79
win ( ) ;
80
- }
81
- else {
80
+ } else {
82
81
loose ( this ) ;
83
82
}
84
83
} ) ;
85
84
}
86
85
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 ;
90
89
}
91
- document . querySelector ( "h1" ) . style . background = pickedColor ;
92
- statusText . textContent = "CORRECT!!!" ;
90
+ document . querySelector ( "h1" ) . style . background = pickedColor ;
91
+ statusText . textContent = "CORRECT!!!" ;
93
92
}
94
93
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 !" ;
98
97
}
99
98
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 ++ ) {
103
102
arr . push ( randomColor ( ) ) ;
104
103
}
105
104
return arr ;
106
105
}
107
106
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