topical media & game development
lib-js-misc-quizhead.js / js
function quizResult(form,questionArray){
totalQuestions=form.totalQuestions.value;
totalCorrect=0;
checkedValue=new Array();
quiz.style.visibility="hidden";
for(counter1=0;counter1<totalQuestions;counter1++){
currentQuestion=eval("form.Q"+String(counter1));
currentAnswer=eval("form.A"+String(counter1));
checkedValue[counter1]="NA";
for(counter2=0;counter2<4;counter2++){
if(currentQuestion[counter2].checked){
checkedValue[counter1]=currentQuestion[counter2].value;
}
}
formComplete=true;
if (checkedValue[counter1]==currentAnswer.value){
totalCorrect++;
}
else if(checkedValue[counter1]=="NA"){
formComplete=false;
break;
}
}
if(formComplete){
for(counter3=0;counter3<totalQuestions;counter3++){
document.write("<p>");
document.write("Question: "+questionArray[counter3][0]+"<br>");
if(questionArray[counter3][5]==checkedValue[counter3]){
document.write("Your Answer: "+questionArray[counter3][checkedValue[counter3]]+" -- Correct<br>");
}
else{
document.write("Your Answer: "+questionArray[counter3][checkedValue[counter3]]+" -- Incorrect<br>");
document.write("Correct Answer: "+questionArray[counter3][questionArray[counter3][5]]+"<br>");
}
document.write("</p>");
}
totalIncorrect=totalQuestions-totalCorrect;
percentage=Math.floor((totalCorrect/totalQuestions*100));
document.write("<p>Result: <br>");
document.write("Total Questions: "+totalQuestions+"<br>");
document.write("Correct Answers: "+totalCorrect+"<br>");
document.write("Incorrect Answers: "+totalIncorrect+"<br>");
document.write("Result: "+percentage+"%</p>");
}
else{
alert("You did not complete the quiz!");
quiz.style.visibility="visible";
}
}
(C) Æliens
20/2/2008
You may not copy or print any of this material without explicit permission of the author or the publisher.
In case of other copyright issues, contact the author.