Async function dolight(){while (true) {// use to loop without just executing await changeColor(3000,'green') await changeColor(1000,'yellow') await changeColor(2000,'red') } } async function changeColor(duration,color){ document.getElementById("light").style.background = color; await sleep(duration) }, function sleep(duration){ return new Promise((resolve)=>{ setTimeout(resolve,duration) }) } dolight()Copy the code