1. function countThreeSeconds() {
  2.     return $.Deferred(function(def){
  3.         var counter = 0,
  4.         timer = setInterval(function () {
  5.  
  6.             if (counter == 3) {
  7.                 console.log("All done. That was three seconds.");
  8.                 window.clearInterval(timer);
  9.                 def.resolve();
  10.  
  11.             } else {              
  12.                 console.log("Not there yet. Counter at: " + counter);
  13.                 def.notify(counter);
  14.             }
  15.             counter++;
  16.         }, 1000);
  17.     }).promise();
  18.  
  19. }