title: Javasacript Countdown timer in Days, Hours, Minute, Seconds
body: <p>I'm trying to create a time-based count down clock. It is not based upon current_dates. The initial time that will be pulled will be from a separate php file. This will be for a browser based-game. When someone clicks the button to initiate this script. it will check if certain requirements are met and if so then this script will initiate. Based upon the level of the object it will pull the initial timer for that proceeding level. Hope that makes sense. Anyhow I based the timer script off of the first code I provide.  </p>
  
  <p>This script only accounts for minutes and seconds. I modified it to include days and hours as well. Somewhere in the process I have messed up and the script doesn't even work at all.  I'm also not quite sure if this would be the best method to calculate this. So, if you have a cleaner method at doing this please share. Thank you in advance.</p>
  
  <p>This script is based off of a minutes / seconds script I saw. Here's the original source:</p>
  
  <pre><code>&lt;span id="countdown" class="timer"&gt;&lt;/span&gt;
  &lt;script&gt;
     var seconds = 60;
     function secondPassed() {
     var minutes = Math.round((seconds - 30)/60);
     var remainingSeconds = seconds % 60;
     if (remainingSeconds &lt; 10) {
        remainingSeconds = "0" + remainingSeconds; 
     }
     document.getElementById('countdown').innerHTML = minutes + ":" + remainingSeconds;
     if (seconds == 0) {
      clearInterval(countdownTimer);
      document.getElementById('countdown').innerHTML = "Buzz Buzz";
     } else {
      seconds--;
     }
     }
     var countdownTimer = setInterval('secondPassed()', 1000);
  &lt;/script&gt;
  </code></pre>
  
  <p>Here is the modified script that I am trying to include days, hours, minutes and seconds.</p>
  
  <pre><code>&lt;span id="countdown"&gt;&lt;/span&gt;
  &lt;script&gt;
       var current_level = 93578;
  
       function timer() {
  
          var days = Math.round(current_level/86400);
          var remainingDays = Math.round(current_level - (days * 86400));
  
          if (days &lt;= 0){
               days = current_level;
          }
  
          var hours = Math.round(remainingDays/3600);
          var remainingHours = Math.round(remainingDays - (hours * 3600));
  
          if (hours &gt;= 24){
               hours = 23;
          }
  
          var minutes = Math.round(remainingHours/60);
          var remainingMinutes = Math.round(remainingHours - (minutes * 60));
  
          if (minutes &gt;= 60) {
               minutes = 59;
          }
  
          var seconds = Math.round(remainingMinutes/60);
  
          document.getElementById('countdown').innerHTML = days + ":" + hours ":" + minutes + ":" + seconds;
  
          if (seconds == 0) {
               clearInterval(countdownTimer);
               document.getElementById('countdown').innerHTML = "Completed";
          }
       }
       var countdownTimer = setInterval('timer()', 1000);
  &lt;/script&gt;
  </code></pre>