title: Handling Recursive Function With setTimeout In A Synchronous Fashion
body: <p>I have the following function and would like to be able to call another function outside of this function and have it run only once this function has completed. I know the setTimeout is what is causing the asynchronous behavior. I've tried promises, but can't figure out how to use the promise in combination with the setTimeout and recursive action. </p>
  
  <p>The basic idea of this function is that it takes a time, we'll say 10 seconds and counts down to 0. Once the countdown reaches zero, then, ideally the next function would run. The setTimeout is used to recursively call the function every 1 second (1000 milliseconds) </p>
  
  <pre><code>const countDown = () =&gt; {
      if (seconds &gt; 0) displayTime(seconds, 'second', '--');
      else if (minutes &gt; 0) {
          displayTime(minutes, 'minute', '--');
          displayTime(59, 'second');
      }
      else if (hours &gt; 0) {
          displayTime(hours, 'hour', '--');
          displayTime(59, 'minute');
      }
  
      seconds = parseInt(secondTwo.innerHTML + secondOne.innerHTML);
      minutes = parseInt(minuteTwo.innerHTML + minuteOne.innerHTML);
      hours = parseInt(hourTwo.innerHTML + hourOne.innerHTML);
  
      if (seconds === 0 &amp;&amp; minutes === 0 &amp;&amp; hours === 0) {
          audio.play();
          endTimer();
      }
  
      countDownId = setTimeout(() =&gt; {
          countDown();
      }, 1000);
  }
  </code></pre>
  
  <p>Let me know if you have any questions or need any clarity! Thanks in advance!</p>