Jump to content

Recommended Posts

Posted

Hello,

 

I have a multiple choice quiz in HTML. My requirement for scoring this quiz seems to be different from every other quiz I have seen on the WWW.

 

This is due mainly, I believe, to the fact that the number of questions involved in this quiz can be from 1 to infinite as the user action brings up the next question from external JS Q&A files.

 

In addition I want the user to see their score amended each time they answer a question, not at the end of the quiz (which theoretically may never happen).

 

 

In the existing code I already determine and provide "Correct" and "Incorrect" messages immediately following the selection of any of the four 'answer' radio buttons.

 

What I need to do now is to find out how I can arrange to:

1 count all the ?Correct? answers - when they occur and add to a 'running' total (RT1)

2 count all the ?Incorrect? answers - when they occur and add to a 'running' total (RT2)

3 calculate:- (RT1/(RT1 + RT2)) x (100/1) = percentage success rate so far.

 

The ?percentage success rate so far? is to be shown in a text field for the user to see.

 

Can anyone advise me what is involved in this and how I should approach it?

 

Pointing me towards an example, if one exists, would be very helpfull.

 

Thanks.

Posted (edited)

jQuery might be your answer: www.jquery.com

 

It is a fantastic Javascript framework, and the code is almost human readable :cool:

 

When people answer correctly, where does the "Correct" and "Incorrect" strings come from? Are they hidden fields that are displayed? Or are they injected into the document (DOM) using Javascript's append or prepend functionalities?

 

In any case, the way to approach it would be to give a class to the "Correct" or "Incorrect" strings and inject them into the DOM using jQuery like so:

 

var correctString = "Correct";
var incorrectString = "Incorrect";

if(your checking condition for correct answer){
   jQuery("div.question1").append(correctString);
}else{
   jQuery("div.question1").append(incorrectString);
}

 

So these strings will be inserted into the HTML depending on how the user answered. So because these tags have a class, this enables you to count their numbers using jQuery: (if you don't understand the following code, then please have a look at jQuery's homepage and documentation)

 

jQuery(function(){
   // jQuery("span.correct") will collect a jQuery object of ALL the spans with class 'correct'
   // .size() method will return the number of items in the object collection, starts at 1 and NOT 0 which is great 
   var RT1 = jQuery("span.correct").size();
   var RT2 = jQuery("span.incorrect").size();
   var successRate = (RT1/(RT1 + RT2)) x (100/1);
})

 

Something along these lines :P

 

Good luck.

Edited by BeeDev
Posted

Thankyou BeeDev,

 

You've given me a lot to think about.

I've only recently started working with JS and am finding it a bit of a struggle not having a background in programming.

Your detailed explanation is very helpful - I'll be using that link today.

 

To answer your questions, finding where Correct and Incorrect comes from is proving difficult. That is to say it seems that the outputs that generate the 'correct' and 'incorrect' messages cannot also be used to increment a running total. (probably my ineptitude tho)

 

I've posted my code below so you can see what I mean:

function responses(){
var temp2=document.instantquiz.theresponse
var temp3=temp2.options[temp2.selectedIndex].text
if (temp3!=solution[dq]&&temp2.selectedIndex!=0)
document.instantquiz.thesolution.value="The correct answer is "+solution[dq]
else if(temp2.selectedIndex!=0)
document.instantquiz.thesolution.value=("CORRECT") 

 

This is where I am at the moment (please don't laugh).


Percentage Success Rate: 
Cheat Mode








 

Oh, go on then, LoL :rolleyes:

 

 

I'll let you know how I get on.

 

Thanks again.

Regards.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Loading...
×
×
  • Create New...