Skip to content

Instantly share code, notes, and snippets.

@imwithsam
Last active October 13, 2015 16:17
Show Gist options
  • Save imwithsam/4f9ead7e0bf58bf0f871 to your computer and use it in GitHub Desktop.
Save imwithsam/4f9ead7e0bf58bf0f871 to your computer and use it in GitHub Desktop.
Countdown
function countdown(seconds, callback){
var i = setInterval(function() {
if (typeof callback === 'function') {
callback(seconds--);
} else {
console.log(seconds--);
}
if (seconds === -1) {
clearInterval(i);
}
}, 1000);
}
countdown(5);
countdown(10, function (i) {
console.log('THIS IS MY CUSTOM CALLBACK!!!', i);
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment