JSFiddle - React, Tailwind, and code Playground

HTML

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

JavaScript

var colors = [];
colors.push({color:"gold", time:4000});
colors.push({color:"red", time:2000});

var numberofTimes = 50;
var $body;
var times = 0;
var currentColor = {};

$(function(){
    $body = $('body');
    changeBG();
});

function changeBG()
{
    currentColor  =  colors[times % colors.length];
    $body.css('background-color',currentColor.color);
    times++;

    if(times<numberofTimes)
       setTimeout(changeBG, currentColor.time);
}