-
Notifications
You must be signed in to change notification settings - Fork 9
/
index.js
55 lines (45 loc) · 1.43 KB
/
index.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
let audioTurn = new Audio("bing.mpeg");
const heading = document.getElementById("Heading")
const bar = document.getElementById("bar")
const autoBtn = document.getElementById("button-3")
const changeBtn = document.getElementById("button-1")
// changeBtn.addEventListener("click",colorChange())
var set = false;
var mytimer
document.getElementById("button-1").onclick = function () {
changeColor()
}
function changeColor() {
let r, g, b, appleColor;
r = Math.round(Math.random() * 256);
g = Math.round(Math.random() * 256);
b = Math.round(Math.random() * 256);
appleColor = 'rgb(' + r + ',' + g + ',' + b + ')';
document.getElementById("Color").style.backgroundColor
= appleColor;
document.getElementById("color-text").innerHTML=
appleColor;
bar.style.backgroundColor = appleColor
audioTurn.play();
}
autoBtn.addEventListener("click",()=>{
bar.classList.add('active');
if(set===false){
mytimer = setInterval(changeColor,7000);
set=true;
}
})
document.getElementById("button-2").onclick =
function(){
audioTurn.play();
let color="white";
document.getElementById("Color").style.backgroundColor
=color;
document.getElementById("color-text").innerHTML=
"White";
bar.style.backgroundColor = `white`
heading.style.color = `white`
bar.classList.remove('active')
clearInterval(mytimer)
set = false
}