New course! Every coder should learn Generative AI!
Try a free lesson0
Cannot change the background color of body using touchstart event listener
Is there any issues with this code? <code> document.body.addEventListener('touchstart', window.onload = function () { const randomColor = getRandomColor(); document.body.style.background = randomColor; }); function getRandomColor() { const letters = '0123456789ABCDEF'; let color = '#'; for (let i = 0; i < 6; i++) { color += letters[Math.floor(Math.random() * 16)]; } return color; } </code>
2 Answers
+ 1
you can replace document.body with window also
on the top