javascript - Timer Start button -
hi i'm making game involves count down timer. want game start when timer button clicked @ moment timer begins on own. have looked @ few different questions answered haven't worked me. suggestions?
var seconds = 60; function secondpassed() { var minutes = math.round((seconds - 30)/60); var remainingseconds = seconds % 60; if (remainingseconds < 10) { remainingseconds = "0" + remainingseconds; } document.getelementbyid('countdown').innerhtml = minutes + ":" + remainingseconds; if (seconds == 0) { clearinterval(countdowntimer); document.getelementbyid('countdown').innerhtml = "times up!!!"; } else { seconds--; } } var countdowntimer = setinterval('secondpassed()', 1000);
add setinterval button's click listener:
var btn = document.getelementbyid('button_id'); btn.addeventlistener('click', function() { setinterval('secondpassed()', 1000); });
Comments
Post a Comment