This is the working solution and comments for anyone who is looking for it!
// JavaScript Document
function validate(theForm) {
//put the questions into an array
var allQuestions = new Array(theForm.q1,
theForm.q2,
theForm.q3,
theForm.q4);
return checkAnswers(allQuestions);
}
//checks all answers
function checkAnswers(allQuestions){
var totalScore = 0; //initialize to 0
//go through each question set
for (var i in allQuestions) {
var temp = allQuestions[i];
//go through each radio button in the current question set
for (var j = 0; j < temp.length; j++) {
//if the correct one is chosen then add 1 to total score
if (temp[j].value == "correct" && temp[j].checked == true) {
totalScore++;
}
}
}
//if the total percentage is more than 75%
if ((totalScore/allQuestions.length) >= .75) {
//alert and move on
alert("Congratulations! Your score of " + totalScore +
" out of " + allQuestions.length + " is very good!");
return true;
}
//otherwise alert and return false
alert("You must get at least 75% correct to pass");
return false;
}