JSFiddle - React, Tailwind, and code Playground
by Rishi Gautam
JavaScript
var arr = ['red', 'blue', 'green'];
var index = 0;
var loopIndex = 0;
var loopMax = 5;
changeColor();
function changeColor() {
setTimeout(function() {
if(loopIndex < loopMax * arr.length) {
if(index === 3) {
index = 0;
console.log('reset to white');
$('body').css('background-color', 'white');
setTimeout(function() {
changeColor();
}, 1000);
} else {
loopIndex++;
console.log('color is', arr[index]);
$('body').css('background-color', arr[index++]);
changeColor();
}
} else {
console.log('Stopped');
}
}, 400);
}