title: Making a timer in Javascript , starting from 00:00:00
body: <p>with this following code </p>
  
  <pre><code>function clock(){
      /*var message = document.getElementById("timer");
      message.innerHTML = "The time is " + Date();
      */
      var msec = 00;
      var sec = 00;
      var min = 00;
  
      msec += 1;
      console.log(min + ":" + sec + ":" + msec);
      if (msec == 60) {
          sec += 1;
          msec = 00;
          console.log(min + ":" + sec + ":" + msec);
          if (sec == 60) {
              sec = 00;
              min += 1;
              console.log(min + ":" + sec + ":" + msec);
              if (sec % 2 == 0) {
                  alert("Pair");
              }
          }
      }
      document.getElementById("timer").innerHTML = min + ":" + sec + ":" + msec;
  }
  </code></pre>
  
  <p>What I wanted to do is a simple timer that starts on a window load, and every milisec it increments the up to 60, which by then resets to 0 and adds 1 to the seconds which when seconds reaches 60, goes to 0 and increments minutes by 1. Sorta like a stopwatch.</p>
  
  <p>It seems I'm not incrementing properly but I don't know how to increment it.</p>
  
  <p>I'm calling the function with a <code>setInterval</code> which I don't know if its right:</p>
  
  <pre><code>var  timer = setInterval(clock(), 1000);
  </code></pre>