I'm trying to change the background color on each click.
var button = document.querySelector("button");
var body = document.querySelector("body");
var color = true;
button.addEventListener("click", function(){
if(color){
body.style.backgroundColor = "purple";
color != color;
}
else if (!color){
body.style.backgroundColor = "green";
}
});
color != color;tocolor = falseand \ or, simplify your function tofunction(){ color ? body.style.backgroundColor = "purple" : body.style.backgroundColor = "green"; };altogether.