Skip to content

Instantly share code, notes, and snippets.

@adhithyan15
Last active December 8, 2018 21:17
Show Gist options
  • Save adhithyan15/4355471 to your computer and use it in GitHub Desktop.
Save adhithyan15/4355471 to your computer and use it in GitHub Desktop.
Coffeescript version of the Countdown.js timer script
###
Countdown.coffee is the coffeescript version of the countdown.js timer script.
Thanks to js2coffee.org
###
countdown = (minutes) ->
tick = ->
#This script expects an element with an ID = "counter". You can change that to what ever you want.
counter = document.getElementById("counter")
current_minutes = mins - 1
seconds--
counter.innerHTML = current_minutes.toString() + ":" + ((if seconds < 10 then "0" else "")) + String(seconds)
if seconds > 0
setTimeout tick, 1000
else
countdown mins - 1 if mins > 1
seconds = 60
mins = minutes
tick()
#You can use this script with a call to onclick, onblur or any other attribute you would like to use.
countdown n #where n is the number of minutes required.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment