It is impossible to make a time counter (seconds) in the pop-up, so that after 3 seconds the window is closed. I want tick 3, then 2, then 1 and the window closes, so this tick how to implement? I know that through the setinterval, but it does not work.

  • one
    Well, describe in more detail. What they did, as they did. And it is not clear to you from the very beginning to explain JS or not. - Dmitry Manannikov

1 answer 1

var counter = 3; var intervalId = setInterval(function(){ console.log(counter--);// вваш способ вывода отсчёта if(counter==0){ clearInterval(intervalId); console.log('close'); // ваш способ закрытия } }, 1000) 
  • Only counter-- it is better to perform after the comparison, so that "3, 2, 1, close" does not turn into "3, 2, close". - nSauk