JSFiddle - React, Tailwind, and code Playground

JavaScript

function randcolor(){
    return ('#' + (~~(Math.random() * 16777215)).toString(16))
}

var $body = $("body"),
    $div = $("<div style='display:none; position: absolute; top:0; left:0; bottom:0; right:0;'>A test text</div>");
    
$div.appendTo($body);

function havefun(){
    $div.fadeIn(1000, function() {
        $body.css("background", randcolor());
        $div.fadeOut(1000, function(){
            $div.css("background", randcolor());
            havefun();
        });
    });
}
                
havefun();