Hi all, Sorry to bother u all, I think i previously post about the quiz script, and i read and research abit here and there,

anyway i manage to write some but found some difficulties,especially about random generator..

I have this several 'set' of question and answer, and i like to view'em random
(e.g: refresh---> What is 1+1=?...with option n aswers, refresh---> What is 1+1=?...with option n aswers, refresh---> What is

1+1=?...with option n aswers, ...etc)

questionarray[0]  ='What is 1+1=?.' 
answer[0]  ='1' 
Adistract[0]  ='2' 
Bdistract[0]  ='22' 
Cdistract[0]  ='11' 
Ddistract[0]  ='0'  
questionarray[1]  ='what is the color of the sky?.' 
answer[1]  ='C' 
Adistract[1]  ='red' 
Bdistract[1]  ='yellow' 
Cdistract[1]  ='blue' 
Ddistract[1]  ='purple'  
questionarray[2]  ='cow is =?.' 
answer[0]  ='D' 
Adistract[0]  ='Tank' 
Bdistract[0]  ='President' 
Cdistract[0]  ='Weapon' 
Ddistract[0]  ='Animal'  
questionarray[3]  ='What is 2+2=?.' 
answer[0]  ='A' 
Adistract[0]  ='4' 
Bdistract[0]  ='22' 
Cdistract[0]  ='11' 
Ddistract[0]  ='0'  .....etc

and also if any of master n gurus here have better suggestion, both on the question array and get (viewing method on browser),

i'll be very thankful.
Anyway, thanks in advance.

Best Regards

~M~

Math.random() along with the article on generating random numbers should get you going. Even though the article uses C/C++, adapting the algorithm to Javascript shouldn't be a big problem.

Thanks for the reply...

Also i've added change in the code (the last one is kinda wrong), here's the 'new' code

questionarray[0]  ='What is 1+1=?.' 
answer[0]  ='1' 
Adistract[0]  ='2' 
Bdistract[0]  ='22' 
Cdistract[0]  ='11' 
Ddistract[0]  ='0'  
questionarray[1]  ='what is the color of the sky?.' 
answer[1]  ='C' 
Adistract[1]  ='red' 
Bdistract[1]  ='yellow' 
Cdistract[1]  ='blue' 
Ddistract[1]  ='purple'  
questionarray[2]  ='cow is =?.' 
answer[2]  ='D' 
Adistract[2]  ='Tank' 
Bdistract[2]  ='President' 
Cdistract[2]  ='Weapon' 
Ddistract[2]  ='Animal'  
questionarray[3]  ='What is 2+2=?.' 
answer[3]  ='A' 
Adistract[3]  ='4' 
Bdistract[3]  ='22' 
Cdistract[3]  ='11' 
Ddistract[3]  ='0'  .....etc

i know this can be done by

var i = Math.round(6*Math.random());
document.write(stemarray[i]);

Thanks

Post a code which can be run / tested by us. Posting incomplete snippets from here and there won't help. Anyways, what is the problem you are facing right now? Does it work, if not, have you taken a look at the Error Console of Firefox (Tools -> Error Console)? Does it show any errors? If it works but not the way you wanted, what is the expected behavior?

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.