Q:

Interval doesn't update text jQuery

I'm using jQuery and setInterval to show countdown in my  element but it doesn't update the text however using console.log I can see that the interval is running properly. Here is the code: 
I call this function in my jQuery:
function startTimer(duration, display) {
  var timer = duration, minutes, seconds,days,hours;
  setInterval(function () {
  days = Math.floor(duration / (60*60*24));
  days_raw = days * (60*60*24);
  hours = Math.floor((duration-days_raw) / (60*60));
  hours_raw = hours * (60*60);
  minutes = Math.floor((duration-(hours_raw + days_raw)) / (60));
  minutes_raw = minutes * (60);
  seconds = Math.floor(duration-(hours_raw + days_raw + minutes_raw));
  seconds_raw = seconds;
  if(days>0)
 {
    if(days===1){
    display.text(days+" Day");
 }
 else
 {
    display.text(days+" Days");}
 }
else if(days<=0)
{   console.log(display);
    display.text(hours+":"+minutes + ":" + seconds);
}

if (--timer < 0) {
  timer = duration;
}
}, 1000);
}

And this is my jQuery code:
jQuery(document).ready(function() {
$('[data-countdown]').each(function() {
 var $this = $(this), finalDate = $(this).data('countdown');
 startTimer(finalDate,$this);
 });
});

The values of .data("countdown") is coming from a php file

A:

The problem was the value of Duration was not getting changed so I added duration--; if(duration<0) return; and it resolved the problem

