How do I make the timer updateable?

  • 0
    Clicking the mouse starts setTimeout (fn, 1000);

    How to make sure that with each next click, the number of times the function is launched in a second does not increase, but the counter is updated before the launch of this function, if within a second we clicked the mouse again?
    JavaScript Anna Flynn, Aug 1, 2020

  • 2 Answers
  • 0
    Delete old handler and start new one

    https: //www.w3schools.com/jsref/met_win_cleartimeo ...
    Anonymous

  • 0
    I honestly did not understand what you want.

    But



    var tm = setTimeout (fn, 1000);

    function fn () {

    clearTimeout (tm);

    // create whatever you want

    }

    Apparently it will help you.

    Ps clicks count in a global variable, and check in the timer

    However, there is a more correct method.

    https://webdevkin.com/posts/frontend/kak-ispolzovat .. .
    Anonymous

Your Answer
To place the code, please use CodePen or similar tool. Thanks you!