-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy path131.js
More file actions
25 lines (23 loc) · 665 Bytes
/
Copy path131.js
File metadata and controls
25 lines (23 loc) · 665 Bytes
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
// setInterval
// console.log("script start");
// setInterval(() => {
// console.log(total);
// console.log(Math.random());
// }, 500);
// console.log("script end");
const body = document.body;
const button = document.querySelector("button");
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 rgb = `rgb(${red},${green}, ${blue})`;
body.style.background = rgb;
}, 1000);
button.addEventListener("click", () =>
{
clearInterval(intervalId);
button.textContent = body.style.background;
});
console.log(intervalId);