We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
1 parent 1a6f494 commit 3220be0Copy full SHA for 3220be0
1 file changed
08_Events/Projects/Unlimited Colors/script.js
@@ -0,0 +1,28 @@
1
+// generate a random color
2
+
3
+const randomColor = function(){
4
+ const hex = "0123456789ABCDEF"
5
+ let color = '#'
6
+ for(let i = 0; i<6; i++){
7
+ color += hex[Math.floor(Math.random() * 16)];
8
+ }
9
+ return color;
10
+};
11
+let intervalId;
12
+const startChangingColor = function(){
13
+ if(!intervalId){
14
+ intervalId = setInterval(changeBgColor, 1000 );
15
16
+ function changeBgColor(){
17
+ document.body.style.backgroundColor = randomColor();
18
19
20
21
+const stopChangingColor = function(){
22
+ clearInterval(intervalId);
23
+ intervalId = null;
24
25
26
+document.querySelector('#start').addEventListener('click', startChangingColor);
27
28
+document.querySelector('#stop').addEventListener('click', stopChangingColor);
0 commit comments