JSFiddle - React, Tailwind, and code Playground
HTML
<div id="target">
</div>
CSS
#target {
height: 50px;
width: 50px;
background: orange;
}
JavaScript
const target = document.getElementById('target');
const colors = ["red", "blue", "purple", "black", "gray", "aliceblue"];
const randomColor = () => {
const randomInt = Math.floor(Math.random() * colors.length + 1);
return colors[randomInt];
}
function f1(newInterval) {
target.style.background = randomColor();
setTimeout(f1, newInterval || 1000);
}
f1();