JSFiddle - React, Tailwind, and code Playground

HTML

<div id="caja"></div>
        
        <p><input type="button" value="Activar" onclick="movimiento()"></p>

CSS

#caja {
                
                position: absolute;
                top: 250px;
                left: 25px;
                background-color: blue;
                width: 200px;
                height: 200px;
            }

JavaScript

function movimiento() {
               
                 setTimeout("movcaja()",2000);
                 setTimeout("movcaja2()",4000);
                 setTimeout("movcaja3()",6000);
                 setTimeout("movcaja4()",8000);
            }
            
            function movcaja() {
                
                document.getElementById("caja").style.left = "250px";
               document.getElementById("caja").style.backgroundColor = "red";
               
            }
            
            function movcaja2() {
                
                document.getElementById("caja").style.left = "500px";
               document.getElementById("caja").style.backgroundColor = "green";
                
            }
            
            function movcaja3() {
                
                document.getElementById("caja").style.left = "750px";
               document.getElementById("caja").style.backgroundColor = "purple";
                
            }
            
            function movcaja4() {
                
                document.getElementById("caja").style.left = "1000px";
               document.getElementById("caja").style.backgroundColor = "yellow";
                
            }