0

I have got code like this:

var a = 5;
var i = setInterval(timer, 1000); 

function timer() {
    if (a < 1) {
        console.log('Reaching Stop');      
        clearInterval(i);

        var endInterval="ok";

    }
    a -= 1;
}
console.log(endInterval);

And the problem is:

How to output endInterval from setInterval?

Uwe Keim
  • 39,551
  • 56
  • 175
  • 291
Chris
  • 1
  • 1
  • 1
    HI@Chris You should add a callback inside the timer function, Means when your condition satisfies then it will return the value of endInterval. Is this what you want? – biswajit-rout May 26 '18 at 18:16
  • 2
    Your question is answered in [Wait until setInterval() is done](https://stackoverflow.com/questions/11055530/wait-until-setinterval-is-done) – Thatalent May 26 '18 at 18:31
  • If you declare the var inside this scope.. cannot had access outside the function – Joel Garcia Nuño May 26 '18 at 18:37

0 Answers0