Javascript Quiz Code

C

C. David Rossen

Hello:

I found a script for a simple multiple choice quiz that I would like to
tailor to a quiz that I want to post on a website. The quiz I want to use
can be found at :

http://mtl.math.uiuc.edu/users/C2Schult/quiz2.html

Here is my problem. I want to be able to use answers with more than one
word or number which requires spaces. When I tried doing that, it did not
recognize the question as being answered. For example, it would not
recognize an answer of Bob Smith unless I put Bob_Smith which I don't want
to do. The answers in the example are all either 1 word or 1 number answers
so I cannot tell from that how to do this. Can someone tell me what I need
to do to be able to use multiple word answers without having to use an
underscore? Thanks for your help.

David
 
M

McKirahan

C. David Rossen said:
Hello:

I found a script for a simple multiple choice quiz that I would like to
tailor to a quiz that I want to post on a website. The quiz I want to use
can be found at :

http://mtl.math.uiuc.edu/users/C2Schult/quiz2.html

Here is my problem. I want to be able to use answers with more than one
word or number which requires spaces. When I tried doing that, it did not
recognize the question as being answered. For example, it would not
recognize an answer of Bob Smith unless I put Bob_Smith which I don't want
to do. The answers in the example are all either 1 word or 1 number answers
so I cannot tell from that how to do this. Can someone tell me what I need
to do to be able to use multiple word answers without having to use an
underscore? Thanks for your help.

David

I don't see the problem.

The answers are merely hardcoded in the JavaScript :

var aKey = new Array(3);
aKey[0]="distributive";
aKey[1]="1/3";
aKey[2]="24/99";

Just include a space in your answer; for example,

aKey[0]="distributive property";

Note, you may have to be concerned with case sensitivity if you allow
free-form answers.
 
C

C. David Rossen

OK..when I change all instances of "distributive" to "distributive
property", it does not recognize the answer as a correct answer. Here are
the places where I changed it:

aKey[0]="distributive property";

<input type="radio" name="q1" value="distributive property"
onClick=studentAns(1,"distributive property") >distributive property<br>

That choice is a correct answer, but along with the other two correct
answers, it is only giving me a 67% score instead of a 100% score so it is
not recognizing "distributive property" as a correct answer.

Any ideas? Thanks.


McKirahan said:
C. David Rossen said:
Hello:

I found a script for a simple multiple choice quiz that I would like to
tailor to a quiz that I want to post on a website. The quiz I want to use
can be found at :

http://mtl.math.uiuc.edu/users/C2Schult/quiz2.html

Here is my problem. I want to be able to use answers with more than one
word or number which requires spaces. When I tried doing that, it did not
recognize the question as being answered. For example, it would not
recognize an answer of Bob Smith unless I put Bob_Smith which I don't want
to do. The answers in the example are all either 1 word or 1 number answers
so I cannot tell from that how to do this. Can someone tell me what I need
to do to be able to use multiple word answers without having to use an
underscore? Thanks for your help.

David

I don't see the problem.

The answers are merely hardcoded in the JavaScript :

var aKey = new Array(3);
aKey[0]="distributive";
aKey[1]="1/3";
aKey[2]="24/99";

Just include a space in your answer; for example,

aKey[0]="distributive property";

Note, you may have to be concerned with case sensitivity if you allow
free-form answers.
 
L

Lasse Reichstein Nielsen

C. David Rossen said:
<input type="radio" name="q1" value="distributive property"
onClick=studentAns(1,"distributive property") >distributive property<br>

This is incorrect HTML. You MUST quote attribute values that contain
spaces for it to work. Otherwise, the value ends right after
"distributive", giving syntactically incorrect Javascript as well.

According to the HTML definition, you MUST quote attribute values that
contain anything but letters, digits, and a few select types of
punctuation. Browsers are more forgiving than the requirement, but still
fails at spaces, greater-than signs, etc.

For good coding practice, you SHOULD quote all attribute values. It saves
yourself from having to remember the exceptions, and it is more stable
in the cases where you make changes, like here.

So:
<label for="q1Id">
<input type="radio" name="q1" id="q1Id" value="distributive property"
onClick='studentAns(1,"distributive property")'>distributive property
</label></br>

(use the label tag for the text associated with the radiobutton. Then you
can click the text as well.)

/L
 
G

Guy Roydor

C. David Rossen a écrit:
OK..when I change all instances of "distributive" to "distributive
property", it does not recognize the answer as a correct answer. Here are
the places where I changed it:

aKey[0]="distributive property";

<input type="radio" name="q1" value="distributive property"
onClick=studentAns(1,"distributive property") >distributive property<br>

That choice is a correct answer, but along with the other two correct
answers, it is only giving me a 67% score instead of a 100% score so it is
not recognizing "distributive property" as a correct answer.

Any ideas? Thanks.

use method replace ex : string.replace(" ","#") in comparaison and
inverse for display
Hello:

I found a script for a simple multiple choice quiz that I would like to
tailor to a quiz that I want to post on a website. The quiz I want to
use
can be found at :

http://mtl.math.uiuc.edu/users/C2Schult/quiz2.html

Here is my problem. I want to be able to use answers with more than one
word or number which requires spaces. When I tried doing that, it did
not
recognize the question as being answered. For example, it would not
recognize an answer of Bob Smith unless I put Bob_Smith which I don't
want
to do. The answers in the example are all either 1 word or 1 number
answers

so I cannot tell from that how to do this. Can someone tell me what I
need

to do to be able to use multiple word answers without having to use an
underscore? Thanks for your help.

David

I don't see the problem.

The answers are merely hardcoded in the JavaScript :

var aKey = new Array(3);
aKey[0]="distributive";
aKey[1]="1/3";
aKey[2]="24/99";

Just include a space in your answer; for example,

aKey[0]="distributive property";

Note, you may have to be concerned with case sensitivity if you allow
free-form answers.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
474,432
Messages
2,571,680
Members
48,796
Latest member
Greg L.

Latest Threads

Top