-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathscripts.js
89 lines (74 loc) · 2 KB
/
scripts.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
var red = document.querySelector("#red");
var green = document.querySelector("#green");
var blue = document.querySelector("#blue");
var result = document.querySelector("#result");
var newcolor = document.querySelector("#newcolor");
var box1 = document.querySelector("#box1");
var box2 = document.querySelector("#box2");
var box3 = document.querySelector("#box3");
var box4 = document.querySelector("#box4");
var box5 = document.querySelector("#box5");
var box6 = document.querySelector("#box6");
var redquantity;
var greenquantity;
var bluequantity;
var mainred;
var maingreen;
var mainblue;
var boxarray = [box1,box2,box3,box4,box5,box6];
var correctclick = false;
function randomise()
{
redquantity = Math.floor(Math.random() * (256 - 0) + 0);
greenquantity = Math.floor(Math.random() * (256 - 0) + 0);
bluequantity = Math.floor(Math.random() * (256 - 0) + 0);
}
function changeh1()
{
red.textContent = redquantity;
green.textContent = greenquantity;
blue.textContent = bluequantity;
var randbox = boxarray[Math.floor(Math.random() * boxarray.length)];
return randbox;
}
function colorise()
{
var rgbstr;
for(var i=0; i<boxarray.length; i++)
{
randomise();
rgbstr = "rgb(" + redquantity + ", " + greenquantity + ", " + bluequantity + ")";
boxarray[i].style.backgroundColor = rgbstr;
}
}
var randbox;
var rgbstr;
function reload(arrlength)
{
randomise();
result.textContent = null;
randbox = changeh1();
mainred = redquantity;
maingreen = greenquantity;
mainblue = bluequantity;
rgbstr = "rgb(" + mainred + ", " + maingreen + ", " + mainblue + ")";
colorise();
randbox.style.backgroundColor = rgbstr;
}
reload();
function afterclick()
{
if(this.style.backgroundColor === rgbstr){
result.textContent = " You are Right!!!";
for(var i=0; i<boxarray.length; i++){
boxarray[i].style.backgroundColor = rgbstr;
}
}
else
this.style.backgroundColor = "white";
}
newcolor.addEventListener("click", reload);
for(var i = 0;i<boxarray.length;i++)
{
boxarray[i].addEventListener("click", afterclick);
}