JSFiddle - React, Tailwind, and code Playground

HTML

<div>Я меняю цвет</div>

CSS

div{
   padding: 30px;
   color: black;
}

.yellow{
    background: yellow;
    color: green;
}

.green{
    background: green;
    color: yellow;
}

.blue{
    background: blue;
    color: white;
}

JavaScript

var arrD = ["yellow", "green", "blue"], i = -1;
setInterval(function(){
  document.querySelector("div").className = arrD[i = ++i == arrD.length ? 0 : i];
    console.log(i);
}, 500);