Cannot change the background color of body using touchstart event listener | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
0

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>

21st Feb 2023, 4:19 PM
Shehara Kavikara
Shehara Kavikara - avatar
2 Answers
21st Feb 2023, 4:23 PM
I am offline
I am offline - avatar
+ 1
you can replace document.body with window also on the top
21st Feb 2023, 4:32 PM
I am offline
I am offline - avatar