JavaScript
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");
HTML
<div id="box">BOX</div>
BOX