-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathfile131.js
41 lines (27 loc) · 917 Bytes
/
file131.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
"use strict";
// setInterval
// console.log("script start");
// setInterval(()=>{
// let total = 0;
// for(let i =0; i <10; i++){
// total += i;
// }
// // console.log(total);
// console.log( Math.random() ); },2000)
// console.log("script End");
// my task : change color after every second and stopes after clicking button
const body = document.body;
const button = document.querySelector("button");
// console.log(body);
const intervalID = setInterval( () => {
const red = Math.floor(Math.random()*256);
const green = Math.floor(Math.random()*256);
const blue = Math.floor(Math.random()*256);
const bgColor = `rgb(${red}, ${green}, ${blue})`;
body.style.backgroundColor = bgColor;
},1000);
button.addEventListener("click", () =>{
console.log(intervalID);
clearInterval(intervalID);
button.textContent = body.style.backgroundColor;
});