Results 1 to 3 of 3

Thread: Dividing quiz into different sections

  1. #1
    Join Date
    Mar 2012

    Dividing quiz into different sections

    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.

    <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]+'&nbsp;&nbsp;'+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]+'&nbsp;&nbsp;'+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 />";

    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.

    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>";
    Link to website: http://rileypriddle.co.nz/space/third.html

    (only the first and second planet works)
    Last edited by waiwhetu; 03-29-2012 at 07:28 PM.

  2. #2
    Join Date
    Dec 2005


    I am just a bit confused as to what it is that you want to accomplish, so bear with me on this...

    I believe you want one 'Score' function that scores all the user's planets questions/responses against the user's answers. That should be easy enough to accomplish, but I'm not sure where your variable array (yourAnswers) is coming from. The link at the top of your post is broken and the second link to your website works, but is quite lengthly.

    The other part of my questions has to do with the 'form function' to which you refer. I don't know to what you are referring. Could you please clarify this portion of your request?
    I understand the 'Score' function for each quiz, but am confused about the 'form' function for each quiz.

  3. #3
    Join Date
    Mar 2012
    The link to the thread is: http://www.webdeveloper.com/forum/sh...highlight=quiz

    What i mean by form function is the code at the top. It is repeated in all of the sections of the quiz. is there a way to only use one code of that code and put it in a class then give each quiz an id?

    i only use checkboxes so i can delete the other switch cases i think.

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
HTML5 Development Center