title: Count from 1 to 24 and then restart
body: <p>I have created a counter that counts from 0 to 24 and when it hits 24:</p>
  
  <pre><code>setInterval(function(){DayAndNight()}, 1000);
  
      var iState = 12;
  
      function DayAndNight()
      {
          //console.log('test');
          switch(iState)
          {
  
              case 1:
              { 
                  document.getElementById("time").innerHTML = "1";  
                  iState++;
                  break;  
              }
  
              case 2:
              {
                   document.getElementById("time").innerHTML = "2";   
                   iState++;
                   break;    
              }     
  
              case 3:
              {
                   document.getElementById("time").innerHTML = "3";
                  iState++;
                  break;
              }
  </code></pre>
  
  <p>and so on untill it hits 24 where I return to iState1:</p>
  
  <pre><code>            case 24:
              {
                  document.getElementById("time").innerHTML = "24";
                  iState = 1;                                 
                  break;                     
              } 
  </code></pre>
  
  <p>This works well, and I can set it to start at iState 12, so it doesn't just count from 0 to 24.</p>
  
  <p>However, I was wondering if there was an easier way of doing this task? This is a lot of code for a simple function. I've experimenting with something like this:</p>
  
  <pre><code>var time = setInterval(function(){TimeNumber();},1000);
  
  function TimeNumber()
  {
    for (var i=0;i&lt;23;i++)
    document.getElementById("time").innerHTML = ???;  
  }
  </code></pre>
  
  <p>But I don't know what the next step is. </p>
  
  <p>I hope that you can guide me in the right direction. </p>