I might just be being dense here... I have a variable timeDiscount
that is true
when page loads. Also when page loads, counter begins. At end of counter, I set timeDiscount
to false
... except that this doesn't seem to work...
In this jsFiddle, clicking the "CLICK" word will alert you to the current state of timeDiscount
, the click returns true even after the counter has stopped. Why is that?
https://jsfiddle.net/df773p9m/4/
function startTimer(duration, display) {
var timer = duration, minutes, seconds;
refreshIntervalId = setInterval(function () {
minutes = parseInt(timer / 60, 10)
seconds = parseInt(timer % 60, 10);
minutes = minutes < 10 ? "0" + minutes : minutes;
seconds = seconds < 10 ? "0" + seconds : seconds;
display.text(minutes + ":" + seconds);
if (--timer < 0) {
clearInterval(refreshIntervalId)
timeDiscount = false;
}
}, 1000);
}
jQuery(function ($) {
var timeDiscount = true
var fiveMinutes = 5,
display = $('#time');
startTimer(fiveMinutes, display);
$("#discount").click(function() {
alert(timeDiscount);
})
});