PDA

View Full Version : quiz in ASP


pinkcat_02
03-12-2003, 10:51 PM
I want to design a quiz as a part of my site. I have 3 kind of questions which are:

1. question + 5 multiple choice answer ----> answer will be choosen by radio button
2. question + 5 options ------>answer will be typed into textbox in the right order (ex/ ABCDE, CADBCE...)
3. question + text box -----> answer will be written in the textbox.

Now my problem is the questions are picked randomly from the database so I wonder how I will be able to display the questions and mark the user because eash question has different lay out and will have different system in checking if the answer is right or wrong like the first type of question they will be selecting a radio button where for the last 2 types it will be writing the answer in the textbox.

Thanks

oracleguy
03-13-2003, 01:30 AM
What you could do is have another column in your table that specifies like type then you could have the diffrent methods built into the page on a select case.

And of course have the correct answer stored in the database.

pinkcat_02
03-13-2003, 02:42 AM
well the thing is i wouldn't know which question is going to be selected as it is randomized system so do I need to use

if...else statement?

but then how will it know which if statement to go?

I am confused :confused:

david7777
03-13-2003, 08:28 AM
If you have a table in you database with the questions, as well as the type (ie: checkbox, or text, etc.) then all you need is:


' Get random question and answers from database / XML
' Now you know what type it is, because a question type is
' stored with each question...
' Then all you need to do format the answers according to the question type:

if qtype = "checkbox" then
' write code for checkbox questions
elseif type = "text" then
' write code for text box questions
elseif type = "radiobutton"
' write code for radio button questions
end if

' or, as oracleguy said, the better solution would be:
select case type ' type is the type of question taken from the table
case "checkbox"
' write code for checkbox questions
case "text"
' write code for text box questions
case "radiobutton"
' write code for radio button questions
end select

Hope i understood what you wanted to do...

raf
03-13-2003, 10:05 AM
you can do that. it will run smootly if you don't have to many questions + if you don't wan't to (interactively) use pictures or more appealing kind a questions (but it wount be more then a regular form then).
it's all a question of how involved you'd like to get with this. If it's just a nice-to-have feature on your site, go for the approach in the previous post and store everything in some tables.

howerver, if you want more ...

if you wan't some nice free third party soft, check this out


http://web.uvic.ca/hrd/hotpot/wintutor/index.htm


In my previous job, i worked for 4 years on screening (building all sorts a test and managing projects to build/implement testapp's) and the best tools i've came accross weren't using asp (or not like that). one of the free available thingy's i made, you can see here (hope it still works. takes a few seconds to load + is in dutch, but you'll get the idea)
http://vdab.be/sector/schoonmaak/ziekenhuis.shtml#

click on poetstest

it's a test where i used the traditional questiontypes + added some other questiontypes to make it a bit more appealing (drag and drop, hotspots). The application that manages these tests (lousy third party soft), creates the tests in advance. There's a designer-module where you compose the question, and the complete code for that question is then generated and stored. The scoring rules are also stored. They use some java-applets to create the more dynamic questiontypes (applets with just a few parameters like immage to use and xy-coordinates of right ansew area). This sort of applets can be found on the web.
Other intresting approaches used XML and XSL. The XML file then contains the questions, alternatives, right answer(s), questiontype etc and the XSL contains all the layout stuff.

building the questions in runtime can slow the proces down. loading the complete test at once (like the example above) also slows down the loading + it doesn't allow much interaction.

in my honest opinion: tests need to be atractive, "personalised", as short as possible. One way of doing that is load one (or a set of question) and select the next question(s) depending on the response of the first. (smaller packages to send, so you can include a picture, have a shorter test because they can be adaptive etc)


if you'd like to build a more complexe test-engine, let me know. I'm considering of building one where web-developpers can create there own tests (using an on-line design module) so that they could link to that test in their site and run it in a popupwindow. I've been looking for this kind a tools and never found one I liked. And probably so where others. Coding it as a professional firm is just to expensive + these IT firms lack the methodological and statistical expertise to build a usefull and flexible engine. (To give you an idea, analyzing the scoring module we needed costed almost 100 000 $ (costs of business experts not included))

pinkcat_02
03-19-2003, 12:43 AM
I have managed to display the questions randomly from the database and as u have suggessted I have used if statements for question types as I have 3 different layouts for my questions.

Now the problem is that as far as they are selected randomly i couldn't give them proper ids to use it for checking if they answered it right or wrong.

Like I can't say if ans1='true' then
score= score+ 1

as I don't really know the number of the questions. To randomize the questions I have been using the feauture of Access autonumber.

What to do now?

david7777
03-19-2003, 08:31 AM
If you can have more then one answer to certain questions, I think you would have to have a question table - eg:

| ID | Question | QType | AnswerID | MaxPoints |

Then you will need an answer table - eg:

| ID | Answer | AnswerID | Points |

The first ID would be there for the sake of having a unique identifier. The AnswerID would correspond to the AnswerID in the question table. There can be duplicates of this AnswerID.

So now, when you get a random question, you get the AnswerID with it. To see if the users' answers are correct, you check the answer table and do a search on all answers with the AnswerID of the question. So now you have all the answers to the question, and you can check if the users' is the same.

Example:

'Random pull of question:

| ID | Question | QType | AnswerID | MaxPoints |
---------------------------------------------------------------------------------------------
| 34 | Which month/s have 28 days in them on a leap year? | CheckBox | 54 | 12 |
---------------------------------------------------------------------------------------------
'...Code for checkbox questions...
'The user only ticks the "February" check box.

'Now go and check the answer table for all answers with AnswerID of 54:
| ID | Answer | AnswerID | Points |
--------------------------------------
| 20 | January | 54 | 1 |
| 21 | February | 54 | 1 |
| 22 | March | 54 | 1 |
| 23 | April | 54 | 1 |
| 24 | May | 54 | 1 |
| 25 | June | 54 | 1 |
| 26 | July | 54 | 1 |
| 27 | August | 54 | 1 |
| 28 | September | 54 | 1 |
| 29 | October | 54 | 1 |
| 30 | Novermber | 54 | 1 |
| 31 | December | 54 | 1 |
--------------------------------------

'So you loop through all these answers, because they are all
'correct, and add points for every correct answer the user has
'choosen. So for this question, the user gets 1 point out of a
'maximum of 12. (8.33%)

Hope it helped :cool:

PS - For those who are wondering:
February ONLY hase 28 days in it on a leap your, while all the others have 28 days in them, plus the extra few... So in actual fact - all months have 28 days in them.
Sorry about the example - its the only question i could think of with multiple answers... :D

raf
03-19-2003, 09:02 AM
Just about linking the answers on the form to your db.

I’m not sure i understood everything you’re trying to do, but this is how it’s normaly done:
- have an asp randomize function to come up with some questionID’s
- select the questions by there ID (each question should have a unique ID which is probably best an autonumber field in a questionstable. Sql statement should be something like:
select variables form table wher questioID In (randomnum1,randomnum2,…)
- run through the recordset and compose the form.
- name the formellements so they refer to the questionID. For instance, radiobuttons from question with questioned=1 should be all part of a group named:q1 (or something like that)
Same for dropdows (name=q1), checkboxes (“name =q1” if there is one checkbox for that question or name=”qx1x1” for alternative 1 of questioned 1)
- the values for the radiobuttons, dropdows, checkboxes can be pulled from the recordset when building the form. (if the questions are independent of eachother)
-when the form is posted, you need to loop through the formcollection with a
“for each box in request.form”-loop
you then dynamically build the sql-insert statement. There you have two option: insert one record at a time (easiest) or build a table and insert all the records at once.
Single record.

For each box in request.form
sql=”insert into table (value,questionID) values(avalue,anid)“
select case Left(box,1)
case q
value=request.form(“box”)
ID=right(box,Len(box) – 1)
Case qx1x1
Other code to get the value and ID, probably with a nested for each box loop to get the selected checkbox etc
End select
Sql=replace(sql,”avalue”,value)
Sql=replace(sql,”anid”,ID)
Execute the sql-satement and check for number of records inserted
Next

You see?

So the ID is traceable in the formellements-names. It probably looks complicated, but it’s doable. If you need more help, just let us know.

Hmm. Is this doable for you ? If you’re not in a hurry, I can write if for you, but that’s probably not the best way to learn it.

raf
03-19-2003, 09:20 AM
Something i forgot. It might clear up some things (or confuse you further).

The steps are:
- select ID-randomly (using ASP)
- select questions and alternatives (=possible answers)
- display questions and alternatives
- register the alternatives they chose (1,2,3… or 1and2, …)
- score the test --> select the value associated with the chosen alternative

Don’t try to compute the value after they submitted the form. First register the alternatives, insert them in the database, and then compute the score.

It then is also easier to show a detailed testreport to the user, with the alternatives he choose and the correct ones etc.

Trust me. It’ll give you more flexability (you can change the values for the alternatives more easily, you can compute values for a combination of alternatives on different questions, easier for analyzing the results etc etc)