Skip to content
Snippets Groups Projects
timer.js 1.23 KiB
var time = 0;
var timer_running = false;
var timer_timeout;
var time_string="";

function startStop()
{
  if (!timer_running)
  {
    time=0;
    timer_running = true;
    increment();
    document.getElementById("startStop").innerHTML = "STOP";
    document.getElementById('startStop').style.backgroundColor="#e23047";
    send_goal();
  }
  else
  {
    timer_running = false;
    document.getElementById("startStop").innerHTML = "START";
    document.getElementById('startStop').style.backgroundColor="SeaGreen";
    cancel_goal();
  }
}

function increment()
{
  if (timer_running)
  {
    timer_timeout = setTimeout(
      function()
      {
          if(timer_running)
          {
            time++;
            var mins = Math.floor(time/10/60);
            var secs = Math.floor(time/10 % 60);
            var tenths = time % 10;
            if (mins < 10) {
              mins = "0" + mins;
            }
            if (secs < 10) {
              secs = "0" + secs;
            }
            time_string = mins + ":" + secs + ":" + "0" + tenths;
            localStorage.setItem('attempt_time', time_string);
            document.getElementById("timer_output").innerHTML = time_string ;
            increment();
          }
      },100);
  }
}