Jump to content

Generating Time Intervals


Nohana

Recommended Posts

Is there any simpler way to generate a wait time between events other than using setTimeout() and clearTimeout()?Take for instance the following example:

--JAVASCRIPT--var count=100;function setCountdown() {if(count > 0 ) count--;setTimeout("setCountdown()", 1000);}--HTML--<input type="button" onclick="setCountdown()" />

Isn't calling the function over and over hard on the browser? What's more, if the user keeps clicking on the button, the countdown would go faster than it should and I'd need to add another line of code to prevent this. Isn't there a way to get the same result using a looping such as while or for statement?

Link to comment
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...