console
const app = document.getElementById('app');
function sleep(duration) {
return new Promise(resolve => {
setTimeout(resolve, duration);
})
}
function changeColor(duration, color) {
return new Promise(resolve => {
app.style.background = color;
sleep(duration).then(resolve);
})
}
function main() {
return new Promise(resolve => {
changeColor(3000, 'red').then(() => {
changeColor(2000, 'yellow').then(() => {
changeColor(1000, 'green').then(() => {
main();
})
})
})
})
}
main()
<div id="app"></div>
#app{
width: 100px;
height: 100px;
background: white;
}