DEV Community

CodeMonk
CodeMonk

Posted on

Best ES6 version of JavaScript of generating random colors using time interval

const body = document.getElementsByTagName('BODY')[0];

setInterval(function () {
const random = Math.floor(Math.random() * 16777215)
.toString(16)
.padStart(6, '0');
body.style.backgroundColor = '#' + random;
}, 5500);

Top comments (0)