function victoryDance(element) { // start the animation element.classList.add("animate"); // after 2 seconds start the clean up setTimeout(() => { // stop the animation element.classList.remove("animate"); // fade after 300 ms setTimeout(() => { // fade the element out element.classList.add("fade-out"); // after 300 ms, remove the element setTimeout(() => { element.parentNode.removeChild(element); }, 300); }, 300); }, 2000); } function victoryDance(element) { // start the animation element.classList.add("animate"); Util.wait(2) .then( wait => { element.classList.remove("animate"); return wait(.3); }) .then( wait => { element.classList.add("fade-out"); return wait(.3); }) .then( wait => { element.parentNode.removeChild(element); }); } Util.wait(1) .then(wait => { alert(1); return wait(2);…