title: javascript timers and highscore
body: <p>Hi i would like to use a stop watch to time a users interaction on my html page. Once they click the stop button i want to record their high score time and replace the high score every time a better time happens. i have my stop watch working, but not sure how to figure out the high score part.</p>
  
  <p>my code for html is:</p>
  
  <pre><code>     &lt;body&gt;
    &lt;fieldset&gt;
              &lt;legend&gt;Stop Watch&lt;/legend&gt;
              &lt;input type="button" id="start" value="Start"&gt;
              &lt;input type="button" id="stop" value="Stop"&gt;
              &lt;input type="button" id="reset" value="Reset"&gt;
              &lt;span id="s_minutes"&gt;00&lt;/span&gt;:
              &lt;span id="s_seconds"&gt;00&lt;/span&gt;:
              &lt;span id="s_ms"&gt;000&lt;/span&gt;
              &lt;span id = "highscore"&gt;&lt;/span&gt;
          &lt;/fieldset&gt; 
  
  
  parts of my javascript code is here:
  
  "use strict";
  var $ = function(id) { return document.getElementById(id); };
  
  var stopwatchTimer;
  var elapsed = { minutes:0, seconds:0, milliseconds:0 }; 
  
  
       var padSingleDigit = function(num) {
              return (num &lt; 10) ? "0" + num : num;
          };
  
          var tickStopwatch = function() {    
              // increment milliseconds by 10 milliseconds
              elapsed.milliseconds = elapsed.milliseconds + 10;
  
              // if milliseconds total 1000, increment seconds by one and reset milliseconds to zero
              if (elapsed.milliseconds === 1000) {
                  elapsed.seconds++;
                  elapsed.milliseconds = 0;
              }
              // if seconds total 60, increment minutes by one and reset seconds to zero
              if (elapsed.seconds === 60) {
                  elapsed.minutes++;
                  elapsed.seconds = 0;
              }
  
              //display new stopwatch time
              $("s_minutes").firstChild.nodeValue = padSingleDigit(elapsed.minutes);
              $("s_seconds").firstChild.nodeValue = padSingleDigit(elapsed.seconds);
              $("s_ms").firstChild.nodeValue = elapsed.milliseconds;
          };
  
          // event handler functions
          var startStopwatch = function() {  
  
              tickStopwatch();
              stopwatchTimer = setInterval(tickStopwatch, 10);
          };
  
          var stopStopwatch = function() {
              // stop timer
              clearInterval(stopwatchTimer);
              var score ;
              var highscore=0;
             score = getTime();
  
              if (score&gt;highscore){
  
              highscore== score;
              }
              $("highscore").firstChild.nodeValue = highscore;
  
          };
  
          var resetStopwatch = function() {
              // stop timer
              clearInterval(stopwatchTimer);
  
              // clear elapsed object and stopwatch display
              elapsed = { minutes:0, seconds:0, milliseconds:0 }; 
  
              $("s_minutes").firstChild.nodeValue = "00";
              $("s_seconds").firstChild.nodeValue = "00";
              $("s_ms").firstChild.nodeValue = "000";
          };
  
          window.onload = function() {
  
  
              $("start").onclick = startStopwatch;
              $("stop").onclick = stopStopwatch;
              $("reset").onclick = resetStopwatch;
          };
  </code></pre>