title: Javascript quiz timer
body: <p>Hi I am making a quiz using javascript but am struggling to put in a functioning countdown timer. This may be a simple question but how can I make it so that once the timer reaches zero it'll submit the quiz and tell the user times up? I have tried a few different ways but to no avail. Any help is appreciated.</p>
  
  <p>My code for the countdown timer:</p>
  
  <pre><code>&lt;script&gt;
  
  var total_seconds = 30*1;
  var c_minutes = parseInt(total_seconds/60);
  var c_seconds = parseInt(total_seconds%60);
  
  function CheckTime(){
  document.getElementById("quiz-time-left").innerHTML
  = 'Time Left: ' + c_minutes + ' minutes ' + c_seconds + ' seconds ' ;
  
  if(total_seconds &lt;=0){
  setTimeout('document.quiz.submit()',1);
  } else {
  total_seconds = total_seconds -1;
  c_minutes = parseInt(total_seconds/60);
  c_seconds = parseInt(total_seconds%60);
  setTimeout("CheckTime()",1000);
  }}
  setTimeout("CheckTime()",1000);
  &lt;/script&gt; 
  </code></pre>
  
  <p>My code for the quiz:</p>
  
  <pre><code>    &lt;form name="form" onsubmit="return score()"&gt;
      &lt;h3&gt;1. How many yellow cards equal a red card in football?&lt;/h3&gt;
      &lt;input type="radio" name="q1" value="a"&gt;a. 1&lt;br&gt;
      &lt;input type="radio" name="q1" value="b"&gt;b. 2&lt;br&gt;
      &lt;input type="radio" name="q1" value="c"&gt;c. 3&lt;br&gt;
      &lt;input type="radio" name="q1" value="d"&gt;d. 4&lt;br&gt;
  
      &lt;form name="form" onsubmit="return score()"&gt;
      &lt;h3&gt;1. How many yellow cards equal a red card in football?&lt;/h3&gt;
      &lt;input type="radio" name="q2" value="a"&gt;a. 1&lt;br&gt;
      &lt;input type="radio" name="q2" value="b"&gt;b. 2&lt;br&gt;
      &lt;input type="radio" name="q2" value="c"&gt;c. 3&lt;br&gt;
      &lt;input type="radio" name="q2" value="d"&gt;d. 4&lt;br&gt;
  
      &lt;form name="form" onsubmit="return score()"&gt;
      &lt;h3&gt;1. How many yellow cards equal a red card in football?&lt;/h3&gt;
      &lt;input type="radio" name="q3" value="a"&gt;a. 1&lt;br&gt;
      &lt;input type="radio" name="q3" value="b"&gt;b. 2&lt;br&gt;
      &lt;input type="radio" name="q3" value="c"&gt;c. 3&lt;br&gt;
      &lt;input type="radio" name="q3" value="d"&gt;d. 4&lt;br&gt;
      &lt;br&gt;
      &lt;input type="submit" id="sendA" value="Submit"&gt;
      &lt;br&gt;
      &lt;p id="p"&gt;&lt;/p&gt;
  
  &lt;/form&gt;
  
  &lt;/html&gt;﻿
  
  &lt;script&gt; 
  
  function score()
  {
      //Referencing the value of the questions
      var q1 = document.forms.form.q1.value;
      var q2 = document.forms.form.q2.value;
      var q3 = document.forms.form.q3.value;
  
      //Array for the questions
      var questions = [q1, q2, q3];
  
      //Answers for each question
      var answers = ["b", "b", "b"];
  
      //variable to keep track of the points
      var points = 0;
      var total = 3;
      //max score 
  
      //Making use of a for loop to iterate over the questions and answers arrays
      for (var i = 0; i &lt; total; i++)
      {
      if (questions[i] == answers[i]) {
              points = points + 1; //Increment the score by 2 for every correct answer given
          }
      }
  
      //CSS for questions
      var q = document.getElementById("p");
  
      q.style.fontSize = "40px";
      q.style.textAlign = "center";
      q.innerHTML = "You got " + points + " out of " + total;
  
      return false;
  }
  
      &lt;/script&gt;
  </code></pre>