JSFiddle - React, Tailwind, and code Playground
JavaScript
var colorSwitch = 'gold';
$('body').css('background-color', colorSwitch);
var ind = 0;
var myTimer = setInterval(function() {
if (ind < 5) {
$('body').css('background-color', colorSwitch);
}
ind++;
console.log('color switching code fired ' + ind);
if (ind > 5) {
clearInterval(myTimer);
clearInterval(switch1);
clearInterval(switch2);
}
}, 2000);
var switch1 = setInterval(function() {
if (colorSwitch === 'gold') {
colorSwitch = 'red';
console.log('switched to red');
}
}, 4000);
var switch2 = setInterval(function() {
if (colorSwitch === 'red') {
colorSwitch = 'gold';
console.log('switched to gold');
}
}, 2000);