I can't seem to get the counter to countdown. I tried wrapping it all in a giant function and putting setInterval in the click function and nothing seems to get the count down to show.
$(document).ready(function(){
function createTimer(){
var counter = 5;
var timer = null;
var counterBox = function(){ $(".numberbox").html("counter:"+ ' '+counter )}
$("#button1").click(function(){
counterBox()
})
var timer = setInterval(function(){
counter--;
if (counter >= -1){
counterBox.html("counter:"+ ' '+counter )
}
if (counter === 0)
clearInterval(timer)
else {clearInterval(timer)}
}, 1000);
};
createTimer()
});/*document end */
I can't seem to get the counter to countdown. I tried wrapping it all in a giant function and putting setInterval in the click function and nothing seems to get the count down to show.