The code below will give you an example of a JavaScript that you can use to create fill-in style questions for your students. Any variables that need to be changed are highlighted in blue. The comments, which explain what the code does, are highlighted in pink. If you want to see a working copy of this M&M quiz, visit the Mathematics Vocabulary Quiz.
<html><body bgcolor="#f5f5f5">
<p> </p>
<p> </p>
<h1>Mathematics Vocabulary Quiz</h1>
<script language="JavaScript">
<!--
NumCorrect = 0
numberQuestions = 4
/*Declare the array. The size of your array is one more than the number of questions you are asking. Arrays begin at position 0. We will be putting the students name in position 0.*/
var AA=new Array(numberQuestions + 1);
function first( ) {
/*This places the name of the person taking the quiz into the 0th position of the array. Remember that arrays begin at position 0. This will be the persons name.*/
AA[0] = document.questions.input0.value
/*The series of if statements below will check if the
answer entered by the student is correct.
The function toLowerCase() automatically converts the answer typed in to lower case. That
allows
the script to not be case sensitive. In the script below, you will need to change the
answers to the
correct answers for your questions.*/
if (document.questions.input1.value.toLowerCase() == "slope"){
NumCorrect += 1
AA[1] = "correct" }
else
AA[1] = "Sorry, the correct answer is the slope."
if (document.questions.input2.value.toLowerCase() == "quadratic"){
NumCorrect += 1
AA[2] = "correct" }
else
AA[2] = "Sorry, the correct answer is the Quadratic formula."
if (document.questions.input3.value.toLowerCase() == "pythagorean"){
NumCorrect += 1
AA[3] = "correct" }
else
AA[3] = "Sorry, the correct answer is the Pythagorean theorem."
if (document.questions.input4.value.toLowerCase() == "euler"){
NumCorrect += 1
AA[4] = "correct" }
else
AA[4] = "Sorry, the correct answer is Leonhard Euler."
/*Opens a new window to display the choices selected by the user and the percentage correct. If you ask more than 4 questions, then just copy/paste the line "Number 1 is: "+AA[1] +"<br><br>"+ changing the 1 to the appropriate question number.*/
results=window.open("","","height=400,width=250,scrollbars=yes")
results.document.open();
results.document.write ("<html>" +
"<head><title>Answers</title>"+
"<body bgcolor='cc9999' text='00000'>"+
"<hr>"+"<BR>" +
"Number 1 is: "+AA[1] +"<br><br>"+
"Number 2 is: "+AA[2] +"<br><br>"+
"Number 3 is: "+AA[3] + "<br><br>"+
"Number 4 is: "+AA[4] +"<br><br>"+
"<br><br>"+
AA[0] + ", you got "+NumCorrect+" correct out of "+ numberQuestions + "."+"<br><br>" + "Your score is "+ Math.round((NumCorrect/ numberQuestions) * 100)+" %."
+"<br><br></body></html>");
results.document.close();
}
//-->
</script>
<p><b>Given each of the questions below, type in the correct response. Although capitalization does not count, spelling does!</b></p>
<form NAME="questions">
<p>Please enter your name <input size="35" type="text" name="input0" rows="1" cols="50"></p>
<p>1. What does the formula
<img src="slope.gif" width="144"
height="54" alt="(y2 - y1)/(x2 - x1)" align="middle">represent?<br>
<br><input size="15" type="text" name="input1" rows="1"> <br><br></p>
<p>2. What does the formula
<img src="quad.gif" width="224"
height="66"alt="x = (-b +/- sqrt(b^2 - 4ac)) / 2a"
align="middle"> represent?<br><br>
<input size="15" type="text" name="input2" rows="1"><br><br></p>
<p>3. What is the name of the formula <img src="pythag.gif" width="143" height="36" alt="a^2 + b^2 = c^2" align="middle"> ?<br><br>
<input size="15" type="text" name="input3" rows="1" cols="25"> <br><br></p>
<p>4. The formula <img src="euler.gif" width="126" height="33" alt="e^(i * pi) + 1 = 0" align="middle"> is said to contain the five most famous numbers in Mathematics. Who is credited with its discovery?<br><br>
<input size="15" type="text" name="input4" rows="1"> <br><br></p>
</form>
<form>
<p><input type="button"
name="answers" value="Click here for answers"
onclick="first()">
<input type="button" name="close" value="Click here to close
answer window" onclick="results.close();"> </p>
</form>
<p>Copyright © 2002 Donna Tupper.<br>
<br>
</p>
</body>
</html>