My quiz code is based on the quiz JMRKER posted on this thread: http://www.webdeveloper.com/forum/sh...highlight=quiz
im trying to make multiple quizzes using the code above.
I have many a score function for form and score function for each quiz and was wondering if i could somehow just use 1 form and score function to cut down on the code length.
Code:<script type="text/javascript"> var str = ''; var tmpr = []; var resp = ['a','b','c','d','e','f','g','h','i','j']; // allows for up to 10 responses (can have more) for (q=1; q<QR.length; q++) { str += '<li>'+QR[q][1]+'</li><br />'; tmpr = QR[q][2].split('|'); switch (QR[q][0]) { case 'RB' : for (var r=0; r<tmpr.length; r++) { str += '<input type="radio" name="q'+q+'" value="'+resp[r]+'"'; str += ' onClick="Engine('+q+',this.value,\''+QR[q][0]+'\')">'; str += resp[r]+' '+tmpr[r]+'<br />'; } break; case 'CB' : for (var r=0; r<tmpr.length; r++) { str += '<input type="checkbox" id="q'+q+'_'+r+'" name="q'+q+'" value="'+resp[r]+'"'; str += ' onClick="EngineCB('+q+',this.value,'+tmpr.length+')">'; str += resp[r]+' '+tmpr[r]+'<br />'; } break; case 'SB' : str += '<select name="q'+q+'" size="1" id="q'+q+'"'; str += ' onClick="Engine('+q+',this.value,\''+QR[q][0]+'\')">'; for (var r=0; r<tmpr.length; r++) { str += '<option value="'+resp[r]+'">'; str += tmpr[r]+'</option>'; } str += '</select>'; break; /* test code for future entries -- not implemented yet case 'CBM' : break; case 'SBM' : str += '<select name="q'+q+'" size="1" id="q'+q+'"'; str += ' onClick="Engine('+q+',this.value,\''+QR[q][0]+'\')" multiple>'; for (var r=0; r<tmpr.length; r++) { str += '<option name="q'+q+'" value="'+resp[r]+'">'; str += tmpr[r]+'</option>'; } str += '</select>'; break; */ default : str += q+': Invalid type: '+QR[q][0]; break; } str += "<br><p />"; } document.write(str); </script>
Check to see if score matches the answers in the array QE. and then display the explaination if the user gets the answer wrong (explainAnswer1 array). For the 2nd quiz i just call a new array list (QR2) and create a new function score2.
Link to website: http://rileypriddle.co.nz/space/third.htmlCode:function Score1(){ score = 0; var tmp = ''; var answerText = "<body background='bg.png'><font size='5' face='arial' color='white'>Score</font></body><font face='arial' color='white'>"; // alert('Size of QR: '+QR.length); for (var i=1; i<QR.length; i++) { answerText = answerText+"<br><u>Question: "+i+" Your answer: "+yourAns[i]+"<br></u>"; tmp = QR[i][3]; if (QR[i][0] == 'CB') { tmp = tmp+'|'; } // alert(i+' : '+tmp+' : '+yourAns[i]+'\n\n'+answerText+'\n\n'); if (tmp != yourAns[i]) { answerText = answerText+"<br><font color='red'>Incorrect. The correct answer was <b>"+QR[i][3]+"</b></font><br>"+explainAnswer[i]+"<br>"; } else { answerText = answerText+" <br><font color='green'>You got this one right! </font><br>"; score++; } }
(only the first and second planet works)


Reply With Quote
Bookmarks