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?

  • To get started, click the править button and add your code via the "Code snippet to ..." functionality - it is indicated like this in the editor - <> (on the file icon) - InDevX
  • that's all i added - Nikita Krasnobaev
  • 2
    Because if (x == 3) checking is performed once, when x===0 . - Stepan Kasyanenko
  • Thanks @StepanKasyanenko - Nikita Krasnobaev
  • one
    this is a very evil way of animation - Stranger in the Q

0