True/False Question form

1. George Washington was the first president of the United States. True False

2. Tucson is the capital of Arizona. True False

3. Guam is an island in the Caribbean. True False

4. JavaScript is easier to learn than Java. True False

5. Mhz refers to how much memory a computer has. True False

<SCRIPT>

function tester(form) {
     var percent;
     var correct = 0;    

     if (form[0].checked == true) correct++; // OR if (form.No1[0].checked == true) correct++;
     if (form[3].
checked == true) correct++; // OR if (form.No2[1].checked == true) correct++;
     if (form[5].
checked == true) correct++; // etc...
     if (form[6].
checked == true) correct++;
     if (form[9].
checked == true) correct++;

     percent = (correct / 5) * 100;

     if (percent == 100) alert("You got a " + percent + "%. Great Job!");

     if (percent < 100) alert("You got " + correct + " out of 5 correct ( " + percent + "% )");
}

</SCRIPT>

When the Submit button get pressed the onSubmit Event Handler is initiated. onSubmit calls the function tester(this) and also has a return false which causes "nothing" to happen. In other words, return false overwrites the default behavior of submitting the Form's Information to the server.

<FORM onSubmit="tester(this); return false;">

1. George Washington was the first president of the United States.
<
INPUT TYPE="radio" NAME="No1">True             <= Correct form[0] or No1[0]
<
INPUT TYPE="radio" NAME="No1">False

2. Tucson is the capital of Arizona.
<INPUT
TYPE="radio" NAME="No2">True
<INPUT TYPE="radio" NAME="No2">False            <= Correct form[3] or No2[1]

3. Guam is an island in the Caribbean.
<INPUT TYPE="radio" NAME="No3">True
<INPUT TYPE="radio" NAME="No3">False            <= Correct form[5] or No3[1]

4. JavaScript is easier to learn than Java.
<INPUT
TYPE="radio" NAME="No4">True             <= Correct form[6] or No4[0]
<INPUT TYPE="radio" NAME="No4">False

5. Mhz refers to how much memory a computer has.
<INPUT
TYPE="radio" NAME="No5">True
<INPUT TYPE="radio" NAME="No5">False             <= Correct form[9] or No5[1]

<INPUT TYPE="Submit" VALUE="Get Score"> <INPUT TYPE="Reset" VALUE="Clear">