Hello all,
I have a multiple choice quiz that works fairly well. However, instead of it presenting "End of Quiz" message when last question is completed I need it to take the user back to the beginning (question 1) but with no indication to the user that this has been done.
How can I adjust the code to have it do this?
(thanking you in anticipation)
Code:
<script language="JavaScript1.1">
var whichone=1
var tempmn=document.quiz.thequestion
function generatequestions(){
document.quiz.theresponse.selectedIndex=0
if (!document.quiz.cmode.checked||whichone>=total+1||whichone<=0)
document.quiz.thesolution.value=''
if (whichone>=total+1)
tempmn.value="End of quiz"
else{
tempmn.value=whichone+")"+question[whichone]+"\n\n"+"a)"+eval('choice'+whichone+'[1]')+"\n"+"b)"+eval('choice'+whichone+'[2]')+"\n"+"c)"+eval('choice'+whichone+'[3]')+"\n"+"d)"+eval('choice'+whichone+'[4]')
if (document.quiz.cmode.checked)
document.quiz.thesolution.value=solution[whichone]
}
}
function responses(){
var temp2=document.quiz.theresponse
var temp3=temp2.options[temp2.selectedIndex].text
if (temp3!=solution[whichone]&&temp2.selectedIndex!=0)
document.quiz.thesolution.value="Sorry, the correct answer is "+solution[whichone]
else if(temp2.selectedIndex!=0)
document.quiz.thesolution.value=compliments[Math.round(Math.random()*compliments.length-1)]
}
generatequestions()
</script>
Hello Old Pedant.
Thats exactly what I meant, thankyou very much.
I adjusted the code as you described and it worked except for a small glitch. Having completed the last question the next click should take us back to the beginning of the quiz - it took two clicks to do that it then presented the second question not the first.
I adjusted the code by changing 1 to 0 (see red coloured code) and this presented question 1 OK -
Code:
if (whichone>=total+1) whichone = 0;
- however, it still takes two clicks to get us there. Can you see where this can be fixed?
If you need to see any more of the code let me know.
PS I didn't know what the blue code was doing there either so I removed it Thanks again for your time and support.
Since you didn't really give me enough code to really check out your system, I faked it. I got rid of your eval( ) and your question array and just dumped out text to the textarea, for checking purposes.
This works for me. Dunno why you saw odd stuff you did.
By the by...there is something fundamentally wrong with your data structure (that you didn't show us) that you would *need* to use eval( ).
No, wrong is too strong a word. Say "incomplete" perhaps?
I also think you could have done a better job in the presentation, using actual checkboxes along side the answers, instead of dumping the stuff into a textarea.
Hello Old Pedant,
Would it be ok to post a reply that contains a more detailed explanaton of what I wish to achieve and the web page code? (such as it is)
Regards.