title: Having trouble setting up a multiple case countdown timer in javascript
body: <p>I'm setting up a countdown timer that will count down to two different times a day over the course of a week, so a total of 14 different cases. I've tried a switch statement, and an if-else was recommended to me instead. However, I cannot seem to get my code to work, if anybody could help it would be greatly appreciated.</p>
  
  <p>Edit: I Managed to solve it with a switch, but I'm sure it could be cleaner.</p>
  
  <pre><code>var curday;
  var days;
  var hours
  var mins
  var secs;
  var secTime;
  var ticker;
  var diff;
  var nowDate = new Date();
  
  
  
  function getSeconds() {
      var wday = nowDate.getDay();
      var chours = nowDate.getHours();
      var cmins = nowDate.getMinutes();
      var dy; //Sunday through Saturday, 0 to 6
      var countertime;
      var curtime;
      var atime;
  
  
    switch(nowDate.getDay()) {
    case 0: //Sunday
     if (nowDate.getHours() &lt; 17) {
       dy = 0;
       countertime = new Date(nowDate.getFullYear(),nowDate.getMonth(),nowDate.getDate(),17,0,0); //20 out of 24 hours = 8pm
  } else {
      dy = 0;
      countertime = new Date(nowDate.getFullYear(),nowDate.getMonth(),nowDate.getDate(),23,15,0); //20 out of 24 hours = 8pm
  }   
      break;
    case 1:  //Monday
     if (nowDate.getHours() &lt; 10) {
       dy = 1;
       countertime = new Date(nowDate.getFullYear(),nowDate.getMonth(),nowDate.getDate(),10,0,0); //20 out of 24 hours = 8pm
  } else {
      dy = 1;
       countertime = new Date(nowDate.getFullYear(),nowDate.getMonth(),nowDate.getDate(),23,15,0); //20 out of 24 hours = 8pm
  }   
      break;
      case 2:  //Tuesday
      if (nowDate.getHours() &lt; 20) {
       dy = 2;
       countertime = new Date(nowDate.getFullYear(),nowDate.getMonth(),nowDate.getDate(),20,0,0); //20 out of 24 hours = 8pm
  } else {
      dy = 3;
       countertime = new Date(nowDate.getFullYear(),nowDate.getMonth(),nowDate.getDate(),2,0,0); //20 out of 24 hours = 8pm
  }
      break;
      case 3:  //Wednesday
      if (nowDate.getHours() &lt; 10 &amp;&amp; nowDate.getHours() &gt; 2) {
       dy = 3;
       countertime = new Date(nowDate.getFullYear(),nowDate.getMonth(),nowDate.getDate(),10,0,0); //20 out of 24 hours = 8pm
  } else if (nowDate.getHours &gt; 10) {
      dy = 3;
       countertime = new Date(nowDate.getFullYear(),nowDate.getMonth(),nowDate.getDate(),23,15,0); //20 out of 24 hours = 8pm
  }
      break;
      case 4:  //Thursday
      if (nowDate.getHours() &lt; 20) {
       dy = 4;
       countertime = new Date(nowDate.getFullYear(),nowDate.getMonth(),nowDate.getDate(),20,0,0); //20 out of 24 hours = 8pm
  } else {
      dy = 5;
       countertime = new Date(nowDate.getFullYear(),nowDate.getMonth(),nowDate.getDate(),2,0,0); //20 out of 24 hours = 8pm
  }
      break;
      case 5:  //Friday
      if (nowDate.getHours() &lt; 10 &amp;&amp; nowDate.getHours() &gt; 2) {
       dy = 5;
       countertime = new Date(nowDate.getFullYear(),nowDate.getMonth(),nowDate.getDate(),10,0,0); //20 out of 24 hours = 8pm
  } else if (nowDate.getHours &gt; 10) {
      dy = 5;
       countertime = new Date(nowDate.getFullYear(),nowDate.getMonth(),nowDate.getDate(),23,15,0); //20 out of 24 hours = 8pm
  }
      break;
      case 6:  //Saturday
      if (nowDate.getHours() &lt; 14) {
       dy = 6;
       countertime = new Date(nowDate.getFullYear(),nowDate.getMonth(),nowDate.getDate(),14,0,0); //20 out of 24 hours = 8pm
  } else {
      dy = 6;
       countertime = new Date(nowDate.getFullYear(),nowDate.getMonth(),nowDate.getDate(),20,0,0); //20 out of 24 hours = 8pm
  }
      break;
    default:
       dy = 0;
       countertime = new Date(nowDate.getFullYear(),nowDate.getMonth(),nowDate.getDate(),0,0,0); //20 out of 24 hours = 8pm
  }
  
   curtime = nowDate.getTime(); //current time
   atime = countertime.getTime(); //countdown time
  
   diff = parseInt((atime - curtime)/1000);
   if (diff &gt; 0) { curday = dy - nowDate.getDay() }
   else { curday = dy - nowDate.getDay() -1 } //after countdown time
   if (curday &lt; 0) { curday += 7; } //already after countdown time, switch to next week
   if (diff &lt;= 0) { diff += (86400 * 7) }
   startTimer (diff);
  }
  
  function startTimer(secs) {
   secTime = parseInt(secs);
   ticker = setInterval("tick()",1000);
   tick(); //initial count display
  }
  
  function tick() {
   secs = secTime;
   if (secs&gt;0) {
    secTime--;
   }
   else {
    clearInterval(ticker);
    getSeconds(); //start over
   }
  
   days = Math.floor(secs/86400);
   secs %= 86400;
   hours= Math.floor(secs/3600);
   secs %= 3600;
   mins = Math.floor(secs/60);
   secs %= 60;
  </code></pre>