1<script>
2
3 document.getElementById('change').onclick = changeColor;
4
5 function changeColor() {
6 document.body.style.color = "purple";
7 return false;
8 }
9
10</script>
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
1const btn = document.querySelector('button');
2
3function random(number) {
4 return Math.floor(Math.random() * (number+1));
5}
6
7btn.onclick = function() {
8 const rndCol = 'rgb(' + random(255) + ',' + random(255) + ',' + random(255) + ')';
9 document.body.style.backgroundColor = rndCol;
10}