how to use loops in a javascript quiz
<p>I was able to create a quiz using javascript and html. It is a simple quiz with 5 questions, for now only the solution for question one appears when the user is wrong, I tried adding a function  for the other questions but it wont run, I want to find out how do i loop through all the five question to give solution at the bottom of every wrong answer given by the user.</p>

<p><div class="snippet" data-lang="js" data-hide="false" data-console="true" data-babel="false">
<div class="snippet-code">
<pre class="snippet-code-html lang-html prettyprint-override"><code>&lt;HEAD&gt;

&lt;style type="text/css"&gt;
&lt;!--
.bgclr {background-color: white; color: black; font-weight: bold;}
--&gt;

 .hidden {
  display: none;
 }
 
 .visible {
  display: block;
 }
 
&lt;/style&gt;

&lt;script language="JavaScript"&gt;


// Insert scooter questions number of questions
var numQues = 5;

// Insert number of choices in each question
var numChoi = 3;

// Insert number of questions displayed in answer area
var answers = new Array(5);

// Insert answers to questions
answers[0] = "Keep to the left side of the road far as is safe.";
answers[1] = "Road which cross.";
answers[2] = "When a traffic officer order you to do so.";
answers[3] = "Traffic circle where right of way is applicable.";
answers[4] = "(i), (ii) and (iii)";
answers[5] = "A marked pedestrian crossing ahead.";


function getScore(form) {
 showCorrectAnswers();

  var score = 0;
  var currElt;
  var currSelection;
  for (i=0; i&lt;numQues; i++) {
    currElt = i*numChoi;
    for (j=0; j&lt;numChoi; j++) {
      currSelection = form.elements[currElt + j];
      if (currSelection.checked) {
        if (currSelection.value == answers[i]) {
          score++;
  break;
        }
      }
    }
  }
  score = Math.round(score/numQues*100);
  form.percentage.value = score + "%";
  var correctAnswers = "";
  for (i=1; i&lt;=numQues; i++) {
    correctAnswers += i + ". " + answers[i-1] + "\r\n";
  }
  
  form.solutions.value = correctAnswers;
}

function showCorrectAnswers() {
 var q1Inputs = document.querySelectorAll('.q1-inputs input');
 var correctAnswer = document.querySelector('.q1-inputs span');
 var correct = correctAnswer.textContent;
 q1Inputs.forEach(function(element) {
  if (element.checked) {
   if (element.value !== correct) {
    correctAnswer.classList.remove('hidden');
   } else {
    correctAnswer.classList.add('hidden');
   }
  }
 });
}

//  End --&gt;
&lt;/script&gt;

&lt;/HEAD&gt;

&lt;!-- STEP TWO: Copy this code into the BODY of your HTML document  --&gt;

&lt;BODY&gt;

&lt;h3&gt;Scooter quiz by johnson&lt;/h3&gt;

&lt;form name="quiz"&gt;




1. Which rule is considered the most important RULE OF THE ROAD in South Africa?
&lt;ul class="q1-inputs" style="margin-top: 1pt"&gt;
  &lt;li&gt;&lt;input type="radio" name="q1" value="Always be courteous and considerate towards fellow road users."&gt;Always be courteous and considerate towards fellow road users.&lt;/li&gt;
  &lt;li&gt;&lt;input type="radio" name="q1" value="Do not exceed the speed limit."&gt;Do not exceed the speed limit.&lt;/li&gt;
  &lt;li&gt;&lt;input type="radio" name="q1" value="Keep to the left side of the road far as is safe."&gt;Keep to the left side of the road far as is safe.&lt;/li&gt;
  &lt;span class="hidden" style="color:red;"&gt;Keep to the left side of the road far as is safe.&lt;/span&gt;
  
   
&lt;/ul&gt;




2. Sign L9 warns you about... ahead.

&lt;ul style="margin-top: 1pt"&gt;
  &lt;li&gt;&lt;input type="radio" name="q2" value="Where you are also not allowed to park."&gt; Where you are also not allowed to park..&lt;/li&gt;
  &lt;li&gt;&lt;input type="radio" name="q2" value="A railway crossing"&gt;A railway crossing&lt;/li&gt;
  &lt;li&gt;&lt;input type="radio" name="q2" value="Road which cross"&gt;Road which cross&lt;/li&gt;
&lt;/ul&gt;



3.Under what circumstances, if any, are you allowed to drive your motor motor vehicle on the right-hand side of a public road with traffic moving in both directions?
&lt;ul style="margin-top: 1pt"&gt;
  &lt;li&gt;&lt;input type="radio" name="q3" value="When you switch the emergency lights of your vehicle on."&gt;When you switch the emergency lights of your vehicle on.&lt;/li&gt;
  &lt;li&gt;&lt;input type="radio" name="q3" value="When a traffic officer order you to do so."&gt;When a traffic officer order you to do so.&lt;/li&gt;
  &lt;li&gt;&lt;input type="radio" name="q3" value="Under no circumstance."&gt;Under no circumstance.&lt;/li&gt;
&lt;/ul&gt;



4.Sign CC9 is found at ..
&lt;ul style="margin-top: 1pt"&gt;
  &lt;li&gt;&lt;input type="radio" name="q4" value="Traffic circle where right of way is applicable."&gt;Traffic circle where right of way is applicable.&lt;/li&gt;
  &lt;li&gt;&lt;input type="radio" name="q4" value="Dangerous place where roadwork is being done."&gt;Dangerous place where roadwork is being done.&lt;/li&gt;
  &lt;li&gt;&lt;input type="radio" name="q4" value="Sharp curve to the right."&gt;Sharp curve to the right.&lt;/li&gt;
&lt;/ul&gt;

5.You may not obtain a learner’s license if...

&lt;ul style="margin-top: 1pt"&gt;
  &lt;li&gt;&lt;input type="radio" name="q5" value="A first-aid post."&gt; A first-aid post.&lt;/li&gt;
  &lt;li&gt;&lt;input type="radio" name="q5" value="A railway crossing"&gt;A railway crossing&lt;/li&gt;
  &lt;li&gt;&lt;input type="radio" name="q5" value="Road which cross"&gt;Road which cross&lt;/li&gt;
&lt;/ul&gt;








&lt;input type="button" value="Get score" onClick="getScore(this.form)"&gt;
&lt;input type="reset" value="Clear answers"&gt;
&lt;p&gt; Score = &lt;strong&gt;&lt;input class="bgclr" type="text" size="5" name="percentage" disabled&gt;&lt;/strong&gt;&lt;br&gt;&lt;br&gt;
Correct answers:&lt;br&gt;
&lt;textarea class="bgclr" name="solutions" wrap="virtual" rows="10" cols="100" disabled&gt;
&lt;/textarea&gt;
&lt;/form&gt;</code></pre>
</div>
</div>
</p>