Hello everyone, I wrote the code, made the interval to repeat the function, but only there is a problem, I need to stop the interval after 3 repetitions, but for some reason it does not work, here’s the code:
x = 0; objects = [document.querySelector('.circleOne'), document.querySelector('.circleTwo'), document.querySelector('.circleThree')]; function scaleObjects () { setTimeout(function() { objects[0].style.transform = 'scale(1.4)'; objects[2].style.transform = 'scale(1)'; setTimeout(function() { objects[1].style.transform = 'scale(1.4)'; objects[0].style.transform = 'scale(1)'; setTimeout(function() { objects[2].style.transform = 'scale(1.4)'; objects[1].style.transform = 'scale(1)'; x++; }, 500); }, 500); }, 500); } functionInterval = setInterval(scaleObjects, 1500); if (x == 3) { clearInterval(functionInterval); }
What is my problem?
править
button and add your code via the "Code snippet to ..." functionality - it is indicated like this in the editor -<>
(on the file icon) - InDevXif (x == 3)
checking is performed once, whenx===0
. - Stepan Kasyanenko