Results 1 to 1 of 1
Aug 11, 2004, 22:59 #1
- Join Date
- Jul 2004
- 0 Post(s)
- 0 Thread(s)
var isCorrect = new Array();
if(userAns[qNo] == answer[qNo])
let me explain the whole program to you.
Im creating an assessment engine. Every page contains a question followed by three options (radio buttons). The above function accepts a qNo which is the page no of the respective page (e.g. page1.html,page50.html). res1,res2,res3 is are variables holding the checked or unchecked status of the radio button. If checked the value of the radio box is saved in the array 'userAns'. For e.g.,if the qNo is '5' and the right answer is option 1, then calc(5) would assign 'document.form1.r1.value' to userAns. If this userAns is equal to anwer(which is already defined inside the js file), then isCorrect=1 or else isCorrect=0. This is to find out whether the user has given the right answer or not. Likewise in everypage, the isCorrect[qNo] is updated to either '0' or '1'. At the end of the test, the result is displayed in a newpage along with a feedback for wrong answers. At this page, the function is:
document.write('Q.No.'+i+' You did not answer this correct'+'<br>')
document.write('Q.No.'+i+' You answered this question correct'+'<br>');
This function writes the feedback only for the wrong answers. But the problem is that the isCorrect[qNo] in the last page showing as 'undefined'.
Also for every correct answer, a global variable called 'score' is incremented by 10. But at the last page, the value of score still remains '0' even if all questions are correct.
Can u please suggest a way to retain the value of arrays and variables in everypage?