-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathscript.js
70 lines (63 loc) · 2.67 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
var red, green, blue;
var colorlist = document.querySelectorAll(".color");
var numberOfColors = 3;
changeColors()
function eventHandler(){
this.classList.add("selected");
if (this.classList.contains("correct")){
correct(this);
}
else{
this.style.opacity = 0;
document.querySelector(".status").innerHTML = "Try Again";
}
}
function changeColors(){
document.querySelector(".status").innerHTML = "";
document.querySelector(".new").innerHTML = "NEW GAME";
red = Math.floor(Math.random() * 256)
green = Math.floor(Math.random() * 256)
blue = Math.floor(Math.random() * 256)
document.querySelector(".header").style.backgroundColor = "#FFC300";
document.querySelector(".rand-color").innerHTML = "rgb("+ red +", "+ green +", "+ blue +")";
boxNum = Math.floor(Math.random() * numberOfColors) + 1
document.querySelector(".color1").style.backgroundColor = "rgb("+(red-50)+","+green+","+(blue+50)+")" ;
document.querySelector(".color2").style.backgroundColor = "rgb("+(red+50)+","+(green-50)+","+blue+")" ;
document.querySelector(".color3").style.backgroundColor = "rgb("+red+","+(green+50)+","+(blue-50)+")" ;
document.querySelector(".color4").style.backgroundColor = "rgb("+(red-80)+","+green+","+(blue+80)+")" ;
document.querySelector(".color5").style.backgroundColor = "rgb("+(red+80)+","+(green-80)+","+blue+")" ;
document.querySelector(".color6").style.backgroundColor = "rgb("+red+","+(green+80)+","+(blue-80)+")" ;
document.querySelector(".color"+boxNum).style.backgroundColor = "rgb("+red+","+green+","+blue+")" ;
document.querySelector(".color"+boxNum).classList.add("correct");
for (var i=0; i < colorlist.length; i++){
colorlist[i].addEventListener("click", eventHandler)
colorlist[i].style.opacity = 1;
}
}
function correct(){
for (var i=0; i<6; i++){
colorlist[i].style.backgroundColor = "rgb("+red+","+green+","+blue+")" ;
colorlist[i].classList.remove("correct") ;
colorlist[i].classList.remove("selected") ;
colorlist[i].removeEventListener("click", eventHandler)
}
document.querySelector(".status").innerHTML = "Correct!!";
document.querySelector(".header").style.backgroundColor = "rgb("+red+","+green+","+blue+")";
document.querySelector(".new").innerHTML = "PLAY AGAIN";
document.querySelector(".new").setAttribute("onclick", "hard()");
}
function easy(){
numberOfColors = 3
for (var i=3; i < colorlist.length; i++){
colorlist[i].style.display = "none";
}
changeColors()
}
function hard(){
console.log("hi")
numberOfColors = 6
for (var i=0; i < colorlist.length; i++){
colorlist[i].style.display = "inline-block";
}
changeColors()
}