Search code examples
javascriptcountdown

How do Countdown can be repeatedly?


Try to open jsfiddle.net/3hjLb/1/ then click on "Try it" wait until the 0 and click "Try it" and see happen,

How do the "0" it could go back to 10 if you click on "Try it" a second time?


Solution

  • reset your counter variable to 10 before call onclick function

    like this

    <button onclick="javascript:counter=10; countDown()">Try it</button>
    

    See JS Fiddle