A simple quiz  

Test your knowledge of pinnipeds!

1. The largest living pinniped is....
a) the Walrus (Odobenus rosmarus)
b) the Southern Elephant Seal (Mirounga leonina)
c) the Grey Seal (Halichoerus grypus)
d) the Orca (Orcinus orca)

2. The Arctic Bearded Seal (Erignathus barbatus) which has taken up residence in the rivers of Tokyo and Yokohama has been named....
a) Tama-chan
b) Tamagotchi
c) Tamago
d) Doraemon

3. Selkies are examples of....
a) revenants
b) tricksters
c) shapeshifters
d) talking fish

4. The Caribben Monk Seal (Monachus tropicalis) is....
a) common
b) rare
c) highly endangered
d) extinct

5. During the war in Iraq, California Sea Lions (Zalophus californianus) are being used by the US Navy for....
a) suicide missions
b) catching enemy frogmen
c) mascots
d) detecting chemical weapons



This example uses the onClick handlers in the radio buttons to pass the user's choices to the program. Using the this.value construct simplifies the nomenclature of radio buttons in a document. The button calls the Score() function, which checks the user's answers against an answer key and totals the score. This example has been simplified; the original provided explanations for the correct answers and editorialized on the user's expertise.

Code adapted from this quiz on the JavaScript Source site.

Code in the page header
<SCRIPT LANGUAGE="JavaScript">

<!-- 
var ans = new Array;
var yourAns = new Array("", "", "", "", "");

ans[1] = "b";
ans[2] = "a";
ans[3] = "c";
ans[4] = "d";
ans[5] = "b";

function Engine(question, answer) {
yourAns[question]=answer;
}

function Score(){
var score = 0 ;
var answerText = "How did you do?\n===============================";
for(i=1;i<=5;i++){
   answerText=answerText+"\nQuestion "+i+":  ";
  if(ans[i]!=yourAns[i]){
    answerText=answerText+" The correct answer was "+ans[i]+"    \n";
  }
  else{
    answerText=answerText+" Correct! \n";
    score++;
  }
}

answerText=answerText+"===============================\nYour total score is : "+score+"    \n";

alert(answerText);

}
// --> 
</script>

The form

<b>1. The largest living pinniped is....</b><br> <input type=radio name="q1" value="a" onClick="Engine(1, this.value)">a) the Walrus (<i>Odobenus rosmarus</i>)<br> <input type=radio name="q1" value="b" onClick="Engine(1, this.value)">b) the Southern Elephant Seal (<i>Mirounga leonina</i>)<br> <input type=radio name="q1" value="c" onClick="Engine(1, this.value)">c) the Grey Seal (<i>Halichoerus grypus</i>)<br> <input type=radio name="q1" value="d" onClick="Engine(1, this.value)">d) the Orca (<i>Orcinus orca</i>)<p> <b>2. The Arctic Bearded Seal (<i>Erignathus barbatus</i>) which has taken up residence in the rivers of Tokyo and Yokohama has been named....</b><br> <input type=radio name="q2" value="a" onClick="Engine(2, this.value)">a) Tama-chan<br> <input type=radio name="q2" value="b" onClick="Engine(2, this.value)">b) Tamagotchi<br> <input type=radio name="q2" value="c" onClick="Engine(2, this.value)">c) Tamago<br> <input type=radio name="q2" value="d" onClick="Engine(2, this.value)">d) Doraemon<p> <b>3. Selkies are examples of....</b><br> <input type=radio name="q3" value="a" onClick="Engine(3, this.value)">a) revenants<br> <input type=radio name="q3" value="b" onClick="Engine(3, this.value)">b) tricksters<br> <input type=radio name="q3" value="c" onClick="Engine(3, this.value)">c) shapeshifters<br> <input type=radio name="q3" value="d" onClick="Engine(3, this.value)">d) talking fish<p> <b>4. The Caribben Monk Seal (<i>Monachus tropicalis</i>) is....</b><br> <input type=radio name="q4" value="a" onClick="Engine(4, this.value)">a) common<br> <input type=radio name="q4" value="b" onClick="Engine(4, this.value)">b) rare<br> <input type=radio name="q4" value="c" onClick="Engine(4, this.value)">c) highly endangered<br> <input type=radio name="q4" value="d" onClick="Engine(4, this.value)">d) extinct<p> <b>5. During the war in Iraq, California Sea Lions (<i>Zalophus californianus</i>) are being used by the US Navy for....</b><br> <input type=radio name="q5" value="a" onClick="Engine(5, this.value)">a) suicide missions<br> <input type=radio name="q5" value="b" onClick="Engine(5, this.value)">b) catching enemy frogmen<br> <input type=radio name="q5" value="c" onClick="Engine(5, this.value)">c) mascots<br> <input type=radio name="q5" value="d" onClick="Engine(5, this.value)">d) detecting chemical weapons<p> <input type=button onClick="Score()" value="Test your knowledge!"> </FORM>