const box = document.querySelector("#box");
const alternaCor = (cor1, cor2) => {
if (box.style.backgroundColor != cor1) {
box.style.backgroundColor = cor1;
} else {
box.style.backgroundColor = cor2;
}
};
setInterval(alternaCor, 1500, "green", "red");
<div id="box">BOX</div>