-
Notifications
You must be signed in to change notification settings - Fork 0
/
script.js
99 lines (90 loc) · 2.54 KB
/
script.js
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
var colorss = generatecolors(6);
var numsq = 6;
var seq = document.querySelectorAll(".square");
var display = document.querySelector(".head-display");
var picked = pickcolor();
var messageD = document.querySelector("#message");
var header = document.querySelector(".header");
var reset = document.querySelector("#resett");
var easyBtn = document.querySelector("#easyBtn");
var hardBtn = document.querySelector("#hardBtn");
display.textContent = picked;
easyBtn.addEventListener("click",function(){
easyBtn.classList.add("selected");
hardBtn.classList.remove("selected");
colorss = generatecolors(3);
picked = pickcolor();
display.textContent = picked;
for(var i=3;i<seq.length;i++)
seq[i].style.display = "none";
for(var i=0;i<3;i++)
seq[i].style.backgroundColor = colorss[i];
numsq=3;
messageD.textContent = "";
reset.textContent = "NEW COLORS";
});
hardBtn.addEventListener("click",function(){
hardBtn.classList.add("selected");
easyBtn.classList.remove("selected");
colorss = generatecolors(6);
picked = pickcolor();
display.textContent = picked;
for(var i=0;i<6;i++)
{seq[i].style.display = "block";
seq[i].style.backgroundColor = colorss[i];}
numsq=6;
messageD.textContent = "";
reset.textContent = "NEW COLORS";
});
reset.addEventListener("click",function(){
reset.textContent = "NEW COLORS";
colorss = generatecolors(numsq);
picked = pickcolor();
display.textContent = picked;
messageD.textContent = "";
for(var i=0;i<numsq;i++){
seq[i].style.background = colorss[i];
}
header.style.backgroundColor = "rgb(33,97,167)";
});
for(var i=0;i<seq.length;i++){
seq[i].style.background = colorss[i];
seq[i].addEventListener("click",function(){
var clicked = this.style.backgroundColor;
if(clicked==picked)
{
messageD.textContent = "Correct";
changecolors(picked);
header.style.backgroundColor = picked;
reset.textContent = "PLAY AGAIN!";
}
else if(clicked!=picked)
{
this.style.backgroundColor = "#232323";
messageD.textContent = "Try Again!";
}
});
}
function changecolors(color){
for(var i=0;i<seq.length;i++)
{
seq[i].style.backgroundColor = color;
}
}
function pickcolor()
{
var r = Math.floor(Math.random() * colorss.length);
return colorss[r];
}
function generatecolors(x)
{
var arr = [];
for(var i=0;i<x;i++)
{
var a= Math.floor(Math.random() * 256);
var b= Math.floor(Math.random() * 256);
var c= Math.floor(Math.random() * 256);
arr.push("rgb(" + a + ", " + b + ", " + c + ")");
}
return arr;
}