I want to use a for loop to check the questions right in my quiz. I have a variable at the top for the number of questions to loop through. But how do I put the loop index in the command to check the value (document.Quiz.r1.value)? the code is below. Thanks
var numberOfQuestions = 5; // change this to the number of question the quiz contains
var questionsRight = 0;
function addScore()
{
for (i=1;i=numberOfQuestions;i++)
{
var question = document.Quiz.r + i + .value;
if (question!=”correct” || question!=”wrong” )
{
if (question==”correct”)
{
questionsRight = questionsRight +1;
}
}
else
{
prompt(“Please answer all the questions.”);
return;
}
}
document.write(‘You answered ‘+questionsRight+’ questions right out of ‘+numberOfQuestions+’ questions.’);
}
<li>Question 1: Why is the WS3 being Modernized?<br>
<input type=radio name=”r1″ value=”wrong” onclick=””>For a better looking display<br>
<input type=radio name=”r1″ value=”wrong” onclick=””>To provide faster alarm indication<br>
<input type=radio name=”r1″ value=”correct” onclick=””>Some parts are no longer supportable<br><br>
</li>