<button id="changeColorButton">Change Color</button>
// challenge complete the colorGen function. If successful, the background of the page should change when you click on the change-color button.
function colorGen() {
//Your code goes here
}
// Do not change the code below:
// Do not change the code below:
document.body.style.backgroundColor = colorGen();
// Add click event listener to the button
const changeColorButton = document.getElementById('changeColorButton');
changeColorButton.addEventListener('click', function () {
var randomColor = colorGen();
document.body.style.backgroundColor = randomColor;
});
This Pen doesn't use any external CSS resources.
This Pen doesn't use any external JavaScript resources.