Click to See Complete Forum and Search --> : random quiz - learning...


OzThor
02-23-2003, 01:31 PM
ok the attached file is the html file i'm using...

I'm trying to get a quiz working that will randomize the 4 answers to each of 10 questions..

got this to work with a for loop etc...

but can only click 1 answer in the hole quiz... becouse of the 'name' part...
document.write("<input type='radio' value='a' name='question'+yy+'>")

trying to get it to work with question1, question2, etc
the yy var being the counter from the for loop

also keeping track of the right answer, dose the 'value' do this as i have done here...

any tips help....

i still need to do the code to give a score at the end.... next step... but at this time knowing which answer is the right one will do..

the data in the js file is just the data as follow
question.
right answer
wrong answer
wrong answer
wrong answerquestion.
right answer
wrong answer
wrong answer
wrong answer
etc.. for the 10 questions

OzThor
02-23-2003, 07:23 PM
Thanks dave...

i was just going to say i dad worked that one out, but i used the following...
document.write("<input type=\"radio\" value=\"a\" name=\"question"+yy+"\">")
which seams to work ok.... ????

just let me know if what i have done, dose the same...

now I need to work out how to keep track of the right answers so as to do the scoring.... ???

any clues tips?????

OzThor
04-21-2003, 06:18 PM
Dave thanks for your work and time, sorry its been so long to get back to you...


but noted you have set the var's ans[1] to 10 with differen values..

my fult here..

but thay were set to = 'a' as the js file stores the right answer as a in thisquestion[x][2]

my data is formated this way, and there are over 2000 questions that can be used...

and i want to randomize the answers each time the quize is viewed...

this would mean rewriting the order of the answers in the js file or having the code do it for me, knowing that the first one, 'a' is the right one...

sounds about as clear as mud... :)
thanks for you time....

OzThor
04-21-2003, 06:41 PM
sorry people should have added an updated version of the code for you..

here it is,

OzThor
04-21-2003, 07:16 PM
yes that is true dave, that is why I'm trying to randomize the 4 answers with each question, each time the quize is viewed..

the js, file has them stored with the first answer (a) as the right one...

the javascript then randomizes the answers, this part seams to work, my problem is keeping track of the right answer to mark the quiz at the end...

i try doing this by using the var's num1,num2,num3,num4 when seting the value so that in fact... the order of one question could be any of the following...

a,b,c,d or c,d,b,a, or b,d,a,c, or c,a,b,d etc

but a is still the right answer...

I'm trying to keep the value 'a' with the right answer after thay have been randomized, so that I do not have to edit the code ans[x] = 'a' evey time I do a new quiz...

hope that clears things up a little??

OzThor
04-22-2003, 12:54 AM
Ok

document.write("<input type='radio' value=string.formCharCode(96+num1) name='question"+yy+" onClick='storeAns(yy, quiz01.value)'>")

this line of the code sets the input to a radio button, then sets value to one of, a,b,c,d where ver num1 can be 1,2,3, 0r 4, the name is set to question1, to question10, with the ver yy having a value of 1 to 10 for each question in the quiz.
the onClick is ment to pass the value 1 to 10 in yy and a,b,c, or d in the ver quiz01.value

not I'm not shore if I have this right and it is doing what I want it to do, could you point out any errors in this line???

if I can short this line out, it would be a great help...