I am working on a project where I want to display a second countdown after the first one finishes using meteor. The initial timer code looks like this:
sec = 5
@timer = setInterval((->
$('#timer').text sec--
if sec == -1
$('#timer').fadeOut 'fast'
sec=
timer
return
), 1000)
This is how I trigger it: When the template is rendered, I use setTimeout to start the countdown.
Template.selector.rendered = ->
window.setTimeout(startGame, 5000)
timer
Upon starting the game, I need a second countdown. I implemented it as follows:
sec = 5
sw = 0
@timer = setInterval((->
$('#timer').text sec--
if sec == -1
if sw == 0
sw = 1
sec = 20
else if sw == 1
clearInterval timer
return
), 1000)
However, I believe there must be a more efficient way to achieve this.