JSFiddle - React, Tailwind, and code Playground

by ult_combo

HTML

<p id="notice"></p>

JavaScript

//var colorSwitch = 'gold';
(function() {
    var i = 0,
        colorsTimes = [['gold', 'red', 'gold', 'red', 'gold'], 
                       [2000, 4000, 2000, 4000, 2000]];
    
    function switchColors() {
        setTimeout(function() {
            $('body').css('background-color', colorsTimes[0][i]);
            if (++i < colorsTimes[0].length) switchColors();
        }, colorsTimes[1][i]);
    }
    switchColors();
}());

/*
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);

*/