Как реализовать выполнение функции после ее полного окончания(должна закончиться анимация) ? Нужно выполнять в течение 30 секунд, после этого завершаем выполнение. P/S Пробовал сделать через while, но тогда происходит зацикливание и функция выполняется каждую секунду.
Функция:
function createFruit() {
for(let i = 0; i < fruit.length; i++) {
//createFruit
const randomFruit = Math.floor(Math.random() * fruit.length);
const newFruit = document.createElement('div');
const imageFruit = document.createElement('img');
newFruit.id = fruit[randomFruit].id;
newFruit.className = 'fruit';
imageFruit.src = fruit[randomFruit].src;
container.appendChild(newFruit);
newFruit.appendChild(imageFruit);
newFruit.addEventListener("animationend", function() {container.removeChild(newFruit);}, false);
}
}