Quiz with multiple choice answers...

  • discworldian
  • Newbie
  • Newbie
  • discworldian
  • Posts: 5

Post 3+ Months Ago

On my page (http://www.student.kun.nl/m.vanderheijden/whichwitch.html) I made a quiz with multiple choice answers, only I got feedback that the test was too easy to analyze since the choices that lead to the same answer are always in the same order. It seems that I need 10 times as much code to get a random order of answers. Does anyone know a faster way?


MiR
  • Bigwebmaster
  • Site Admin
  • Site Admin
  • User avatar
  • Posts: 9092
  • Loc: Seattle, WA & Phoenix, AZ

Post 3+ Months Ago

So like what do you mean? are the correct answers like the first option all the time for each question?
  • discworldian
  • Newbie
  • Newbie
  • discworldian
  • Posts: 5

Post 3+ Months Ago

No, it's more like the quiz is about 3 characters from a book, and which character you most resemble. so first answer is for character 1, second answer for character 2, third answer for character 3.

MiR
  • Bigwebmaster
  • Site Admin
  • Site Admin
  • User avatar
  • Posts: 9092
  • Loc: Seattle, WA & Phoenix, AZ

Post 3+ Months Ago

I see, well the way you have it right now in the source is like this:

Code: [ Select ]
What's the best way to cure the flu?<br>
<input type="radio" name="q2">Give the patient a medicine made out of rare herbs, which you have researched for years<br>
<input type="radio" name="q2">Give the patient a bottle of scumble and tell him/her to stay in bed if they like<br>
<input type="radio" name="q2">Give the patient a bottle of coloured water, which you say is a very special medicine<br>
  1. What's the best way to cure the flu?<br>
  2. <input type="radio" name="q2">Give the patient a medicine made out of rare herbs, which you have researched for years<br>
  3. <input type="radio" name="q2">Give the patient a bottle of scumble and tell him/her to stay in bed if they like<br>
  4. <input type="radio" name="q2">Give the patient a bottle of coloured water, which you say is a very special medicine<br>


and the way you have your javascript code it simply determines by the order in which they are checked to determine what value they get. What I would do is make each one worth a value and move them around like below:

Code: [ Select ]
What's the best way to cure the flu?<br>
<input type="radio" name="q2" value="2">Give the patient a bottle of scumble and tell him/her to stay in bed if they like<br>
<input type="radio" name="q2" value="3">Give the patient a bottle of coloured water, which you say is a very special medicine<br>
<input type="radio" name="q2" value="1">Give the patient a medicine made out of rare herbs, which you have researched for years<br>
  1. What's the best way to cure the flu?<br>
  2. <input type="radio" name="q2" value="2">Give the patient a bottle of scumble and tell him/her to stay in bed if they like<br>
  3. <input type="radio" name="q2" value="3">Give the patient a bottle of coloured water, which you say is a very special medicine<br>
  4. <input type="radio" name="q2" value="1">Give the patient a medicine made out of rare herbs, which you have researched for years<br>


Then you will have to rewrite your javascript code some to simply determine how many points to add by seeing what value the question is worth (instead of basing it on the order they are placed). I hope that makes sense.
  • discworldian
  • Newbie
  • Newbie
  • discworldian
  • Posts: 5

Post 3+ Months Ago

Thanks, I'll try that.


MiR
  • killercelery
  • Newbie
  • Newbie
  • killercelery
  • Posts: 13
  • Loc: Montréal, Québec

Post 3+ Months Ago

One great feature of html is the possibility to create new elements for a tag. For your problem, I simply created the element witch in each tag input. All you need to change in your current code is the two functions and add the witch element in each input tag like this:

Code: [ Select ]
function update(q)
{    
    if(document.whichwitch.elements[q].checked){
        switch(document.whichwitch.elements[q].witch){
            case "Granny": gscore+=1;
                        break;
            case "Magrat": mscore+=1;
                        break;
            case "Nanny": nscore+=1;
                        break;
        }
    }
}

function rateWitch()
{    
    for(q=0; q<30; q++)
        update(q)
    if (gscore > nscore)
        if (gscore > mscore)
            document.whichwitch.rating.value="Granny"
        else     document.whichwitch.rating.value="Magrat"
    else if (nscore > mscore)
            document.whichwitch.rating.value="Nanny"
       else     document.whichwitch.rating.value="Magrat"
}

...

Do you believe in true love?<br>
input type="radio" name="q0" witch="Granny">Yes<br>
input type="radio" name="q0" witch="Magrat">Yes, but not just one love though<br>
input type="radio" name="q0" witch="Nanny">No<br>
...
  1. function update(q)
  2. {    
  3.     if(document.whichwitch.elements[q].checked){
  4.         switch(document.whichwitch.elements[q].witch){
  5.             case "Granny": gscore+=1;
  6.                         break;
  7.             case "Magrat": mscore+=1;
  8.                         break;
  9.             case "Nanny": nscore+=1;
  10.                         break;
  11.         }
  12.     }
  13. }
  14. function rateWitch()
  15. {    
  16.     for(q=0; q<30; q++)
  17.         update(q)
  18.     if (gscore > nscore)
  19.         if (gscore > mscore)
  20.             document.whichwitch.rating.value="Granny"
  21.         else     document.whichwitch.rating.value="Magrat"
  22.     else if (nscore > mscore)
  23.             document.whichwitch.rating.value="Nanny"
  24.        else     document.whichwitch.rating.value="Magrat"
  25. }
  26. ...
  27. Do you believe in true love?<br>
  28. input type="radio" name="q0" witch="Granny">Yes<br>
  29. input type="radio" name="q0" witch="Magrat">Yes, but not just one love though<br>
  30. input type="radio" name="q0" witch="Nanny">No<br>
  31. ...


simply associate the witches name with the correct answer and you can then mix the questions order as you wish.

Hope this helps.

Post Information

  • Total Posts in this topic: 6 posts
  • Users browsing this forum: No registered users and 121 guests
  • You cannot post new topics in this forum
  • You cannot reply to topics in this forum
  • You cannot edit your posts in this forum
  • You cannot delete your posts in this forum
  • You cannot post attachments in this forum
 
 

© 1998-2014. Ozzu® is a registered trademark of Unmelted, LLC.