JSFiddle - React, Tailwind, and code Playground
HTML
<button onclick="change()">Do you believe in Disco?</button>
CSS
body {
background-color: rgb(0,0,0);
}
button {
margin: auto;
display: block;
}
JavaScript
var on = -1;
function disco() {
var x = Math.floor(Math.random() * 256);
var y = Math.floor(Math.random() * 256);
var z = Math.floor(Math.random() * 256);
var thergb = "rgb(" + x + "," + y + "," + z + ")";
document.body.style.background=thergb;
}
function change() {
on = on*-1;
if (on == true) {
var light = window.setInterval(disco,100);
}
else {
window.clearInterval(light);
}
}