<button id="btn">Click</button>
const colors = ["#ff4242", "#004fd3",]
let index = 0;
document.getElementById('btn').addEventListener("click", () => {
const hexColor = colors[index = Math.abs(--index)];
document.body.style.backgroundColor = hexColor;
});
View Compiled
This Pen doesn't use any external CSS resources.
This Pen doesn't use any external JavaScript resources.