Create an HTML page that has only one button. When the button is clicked, the page starts to change its background color randomly every 5 seconds.
A simple function you can use for the randomizing colors is given.
function randomizer() {
let random_color = "#";
let chars = "0123456789abcdef";
for (var i=0; i < 6 ; i++) {
let char = Math.floor(Math.random()*16);
random_color += chars[char];
}
return random_color;
}
What to Get Out of It
After completing this exercise, you will have a good understanding of how setInterval built in function works, handling of events, how to use Math.random() function to create numbers with in range and more.
Hint
You need to create an event handler for the button you are creating, you can give it an id or class for you to use it as selector. Once the button is clicked, you start the setInterval function and set it every 5 second (5000 ms) to change the background color of the body element. You need to select the body element first and then change the background color of it through .style.backgroundColor property.