html
html
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
<!--
https://www.sololearn.com/Discuss/2992345/js-body-background
-->
<!DOCTYPE html>
<html>
<head>
<title>Page Title</title>
</head>
<body>
</body>
</html>
<!--
Keep learning & happy coding :D
-->
Enter to Rename, Shift+Enter to Preview
css
css
1
2
3
4
body
{
}
Enter to Rename, Shift+Enter to Preview
js
js
1
2
3
4
5
6
7
8
9
10
11
12
const clr = ["red", "green", "blue"];
const b = document.getElementsByTagName("body");
let idx, rnd;
function time() {
idx = Math.floor((Math.random() * clr.length) + 0);
rnd = clr[idx]; // console.log(clr[idx]);
b[0].style.backgroundColor = rnd;
}
// 1 sec
setInterval(time, 1000);
Enter to Rename, Shift+Enter to Preview
BROWSER
Console
Run