1var button = document.querySelector("button");
2
3button.addEventListener("click", function() {
4 const curColour = document.body.style.backgroundColor;
5
6 document.body.style.backgroundColor = curColour === 'red' ? 'blue' : 'red';
7});
8
1var button = document.querySelector("button");
2
3button.addEventListener("click", function() {
4 const curColour = document.body.style.backgroundColor;
5
6 if (curColour === 'red') {
7 document.body.style.backgroundColor = "blue";
8 }
9 else {
10 document.body.style.backgroundColor = "red";
11 }
12});
13