Q:

After Converting Seconds to Minutes & Seconds not displaying

I am trying to display 2700 as 45:00 in javascript, but it is not displayed. I tried this:
var checkStatet = function() {
  jQuery.ajax({
    url: 'check_diffex.php?od=$sdsst'
  }).done(function(data) {
    var o = 2700;
    var minutes = Math.floor(o / 60);
    var seconds = o - minutes * 60;
    var tit = minutes + ':' + seconds;
    var time = jQuery('#rbtntime');
    var timer = setInterval(function() {
      time.html(tit);
      o--;
    }, 1000)
  });
}

checkStatet();

<div id="rbtntime"></div>

I am unable to find out the mistake.

A:

var checkStatet = function() {
  jQuery.ajax({
    url: 'check_diffex.php?od=$sdsst'
  }).done(function(data) {
    //lookup the element just once
    var time = jQuery('#rbtntime');
    //initialize the time
    var o = 2700;

    //start loop delay
    setTimeout(function countdown(){
      var minutes = Math.floor(o / 60);
      var seconds = o % 60;
      //update the time
      time.html(minutes.toString() + ':' + seconds.toString());
      //decrement the time for next iteration
      o--;
      //so long as time is not zero, loop
      if (o > 0) setTimeout(countdown, 1000);
    }, 1000);
  });

}

checkStatet();

