-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathscript.js
51 lines (45 loc) · 1.3 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
var circle=document.getElementsByClassName("btn");
var color=[];
getColor();
function getColor(){
var i;
for(i=0;i<circle.length;i++){
color.push(
`rgb(${Math.floor(Math.random()*255)},${Math.floor(Math.random()*255)},${Math.floor(Math.random()*255)})`
);
}
}
assignColor();
function assignColor(){
var i;
for(i=0;i<circle.length;i++){
circle[i].style.backgroundColor = color[i];
circle[i].setAttribute("data",color[i]);
}
}
var pick=randomColor();
function randomColor(){
var random=color[Math.floor(Math.random()*circle.length)];
colorName.innerText=random;
return random;
}
check();
function check(){
var i;
for(i=0;i<circle.length;i++){
circle[i].onclick=function(){
var getColor=this.getAttribute("data");
if(getColor==pick){
document.getElementById("colorName").innerHTML="CORRECT !!";
document.getElementById("colorName").style.color="darkgreen";
}
else{
document.getElementById("colorName").innerHTML="WRONG !!";
document.getElementById("colorName").style.color="red";
}
}
}
}
function replay(){
window.location.reload();
}