This page contains the code for solarquiz.asp, the active server page (ASP) that drives the Solar System Quiz. The ASP contains a scripting language called VBScript (a computer programming language). Unlike JavaScript embedded in an HTML page, the VBScript in an active server page is not passed to the client computer for processing. The web server processes the VBScript and assembles HTML pages for the client computer. Therefore, the student does not have access to any answers if they examine the HTML code.
The code below represents a simple active server page. It is possible to create active server pages with a high level of sophistication. For example, you could create a script that requires the student to log on to the quiz with an identification code. Then the results of the quiz could be transferred to a database on the server. Periodically the instructor could log on with a password and examine the results of quizzes for all students. Alternatively, the script could be configured to email student scores to the instructor.
<% Language=VBScript%> sets the scripting language to
VBScript
All lines between <% and %>
tags are the script of the program
<% start of the first section of script
If isempty (Session ("QuestionsAnswered")) then checks to
see if an ASP session is active, if not then next 14 lines are executed (i.e. the next 14
lines are executed only when the ASP page is initially accessed)
Session ("QuestionsAnswered") = 0 create the variable QuestionsAnswered
and assign a value of 0
Session ("Correct") = 0 create the variable Correct
and assign a value of 0
Session ("Question1") = 0 create the variable Question1
and assign a value of 0
Session ("Question2") = 0 create the variable Question2
and assign a value of 0
Session ("Question3") = 0 create the variable Question3
and assign a value of 0
Session ("Question4") = 0 create the variable Question4
and assign a value of 0
Session ("Question5") = 0 create the variable Question5
and assign a value of 0
Session ("Question6") = 0 create the variable Question6
and assign a value of 0
Session ("Answer_1") = " " create the variable Answer_1
and assign a value of a space character
Session ("Answer_2") = " " create the variable Answer_2
and assign a value of a space character
Session ("Answer_3") = " " create the variable Answer_3
and assign a value of a space character
Session ("Answer_4") = " " create the variable Answer_4
and assign a value of a space character
Session ("Answer_5") = " " create the variable Answer_5
and assign a value of a space character
Session ("Answer_6") = " " create the variable Answer_6
and assign a value of a space character
End if
The variable QuestionsAnswered keeps track of
the pages that the student has visited. Just prior to display of the first page, this
variable has a value of one. Just prior to display of the second page, this variable has a
value of two. Just prior to display of the third page (quiz results), this variable has a
value of three. The variable Correct keeps track of the number of
questions answered correctly. The variables Question1 through Question6
keep track of each question ( a value of zero indicates the question was answered
incorrectly and a value of one indicates a correct answer). The variables Answer_1
through Answer_6 keep track of the actual answer entered for
each question.
After questions are answered on the first page and the Continue button is
clicked, the script is read again to process the answers.
Since the ASP session is active now, the lines of script above are not executed. Rather,
the line of script below is the first to be executed.
Session ("QuestionsAnswered") = Session ("QuestionsAnswered") + 1 add one to the value of QuestionsAnswered
If Session ("QuestionsAnswered") = 1 then if QuestionsAnswered
equals one, then send the HTML code below to the client computer.
If not, skip down to second section of script, containing ElseIf.
%> end of first section of script
<html> this marks the start of the first HTML page with questions
<head>
<title>ASP Quiz</title>
</head>
<body bgcolor="#008080">
<div align="center"><center>
<table border="1" cellpadding="10" width="95%"
bgcolor="#E1D8A8" bordercolor="#800000">
<tr>
<td><font color="#800040">
<h1><center>Solar System Quiz</center></h1>
<font face="arial">
<p>Directions: answer each question. Then click on the
Continue button.
<form method="POST"
action="http://www.jcu.edu/language/ASP/solarquiz.asp"> start
of form which contains the questions. When the Continue button is
clicked, the contents (answers selected) of this form are sent back to the active server
page (solarquiz.asp) for processing by the sections of script that follow below this HTML
code.
<p>Question 1: What is the name of the largest planet in the solar system?
<select name="Answer1" size="1">
<option selected value="chose">-open and select answer-</option>
<option value="Saturn">Saturn</option>
<option value="Jupiter">Jupiter</option>
<option value="Earth">Earth</option>
</select></p>
<p>Question 2: Which planet has a distinctive ring system?
<p><input type="radio" name="Answer2"
value="Jupiter">Jupiter</p>
<p><input type="radio" name="Answer2"
value="Saturn">Saturn</p>
<p><input type="radio" name="Answer2"
value="Earth">Earth</p>
<p>Question 3: Which planet contains life?
<input type="text" size="7" name="Answer3"
value="">
</p>
<p><input type="submit" value="continue"
name="Action"></p>
</form>
</font>
</font>
</td>
</tr>
</table>
</center></div>
</body>
</html> this marks the end of the first HTML page containing questions
<% start of second section of script
ElseIf Session ("QuestionsAnswered") = 2 then if QuestionsAnswered
equals 2, then the script below is run and the HTML page that follows (second page of
questions) is sent to the client computer. After the questions on the first page are
answered and the Continue button is clicked, the variable QuestionsAnswered
has a value of two because it has been incremented twice by the code line:
Session ("QuestionsAnswered") = Session ("QuestionsAnswered") + 1
Session ("Answer_1") = Request.Form ("Answer1") stores
the student's answer to Question 1 in the variable Answer_1
If Request.Form ("Answer1") = "Jupiter" then checks
to see if Question 1 was answered correctly
Session ("Correct") = Session ("Correct") + 1 if
answered correctly, then variable Correct is incremented by one
Session ("Question1") = Session ("Question1") + 1 if answered correctly, then variable Question1 is
incremented by one
End if
Session ("Answer_2") = Request.Form ("Answer2") stores
the student's answer to Question 2 in the variable Answer_2
If Request.Form ("Answer2") = "Saturn" then checks
to see if Question 2 was answered correctly
Session ("Correct") = Session ("Correct") + 1
Session ("Question2") = Session ("Question2") + 1
End if
Session ("Answer_3") = Request.Form ("Answer3") stores
the student's answer to Question 3 in the variable Answer_3
If Request.Form ("Answer3") = "Earth" or Request.Form
("Answer3") = "earth" then checks to see if
Question 3 was answered correctly (Earth and earth are
accepted as correct answers)
Session ("Correct") = Session ("Correct") + 1
Session ("Question3") = Session ("Question3") + 1
End if
%> end of second section of script
<html> this marks the start of the second HTML page with
questions
<head>
<title>ASP Quiz</title>
</head>
<body bgcolor="#008080">
<div align="center"><center>
<table border="1" cellpadding="10" width="95%"
bgcolor="#E1D8A8" bordercolor="#800000">
<tr>
<td><font color="#800040">
<h1><center>Solar System Quiz</center></h1>
<font face="arial">
<p>Directions: enter the name of each planet to the right of the photo. Then click
on the
Check Answers button.
<form method="POST"
action="http://www.jcu.edu/language/ASP/solarquiz.asp"> start
of form which contains the questions. When the Check Answers button is
clicked, the contents (answers selected) of this form are sent back to the active server
page (solarquiz.asp) for processing by the sections of script that follow below this HTML
code.
<p><img src="earthsm.jpg" width="125" height="94"
alt="photo loading">
<input type="text" size="7" name="Answer4"
value="">
</p>
<p><img src="jupitersm.jpg" width="125" height="94"
alt="photo loading">
<input type="text" size="7" name="Answer5"
value="">
</p>
<p><img src="saturnsm.jpg" width="125" height="94"
alt="photo loading">
<input type="text" size="7" name="Answer6"
value="">
</p>
<p><input type="submit" value="Check Answers"
name="Action"></p>
</form>
</font>
</font>
</td>
</tr>
</table>
</center></div>
</body>
</html> this marks the end of the second HTML page with
questions
<% start of third section of script
Else if QuestionsAnswered does not equal one or
two, then the HTML page below is sent to the client computer. After the questions on the
second page are answered and the Check Answers button is clicked, the
variable QuestionsAnswered has a value of three because it has been
incremented three times by the code line:
Session ("QuestionsAnswered") = Session ("QuestionsAnswered") + 1
%> end of third section of script
<html> now starts the HTML code for the Quiz Results page
<head>
<title>Quiz Answers</title>
</head>
<body bgcolor="#008080">
<div align="center"><center>
<table border="1" cellpadding="10" width="95%"
bgcolor="#E1D8A8"
bordercolor="#800000">
<tr>
<td><font color="#800040">
<h1><center>Quiz Results</center></h1>
<font face="arial">
<% start of fourth section of script. Note that this script is located within an HTML page, unlike the previous
sections of script. This is done so that the script can write part of the HTML page (the
quiz results).
Session ("Answer_4") = Request.Form ("Answer4") stores
the student's answer to Question 4 in the variable Answer_4
If Request.Form ("Answer4") = "Earth" or Request.Form
("Answer4") = "earth" then
Session ("Correct") = Session ("Correct") + 1
Session ("Question4") = Session ("Question4") + 1
End if
Session ("Answer_5") = Request.Form ("Answer5") stores
the student's answer to Question 5 in the variable Answer_5
If Request.Form ("Answer5") = "jupiter" or Request.Form
("Answer5") = "Jupiter" then
Session ("Correct") = Session ("Correct") + 1
Session ("Question5") = Session ("Question5") + 1
End if
Session ("Answer_6") = Request.Form ("Answer6") stores
the student's answer to Question 6 in the variable Answer_6
If Request.Form ("Answer6") = "saturn" or Request.Form
("Answer6") = "Saturn" then
Session ("Correct") = Session ("Correct") + 1
Session ("Question6") = Session ("Question6") + 1
End if
If Session ("Question1") = 1 then i.e. if Question 1 was
answered correctly, then:
Response.Write "<p>Question 1 correct. The largest planet is
Jupiter.</p>"
Else i.e. if Question 1 was not answered correctly, then:
Response.Write "<p>Your answer to Question 1: " & Session
("Answer_1") & ". Correct answer: The largest planet is
Jupiter.</p>"
End if
If Session ("Question2") = 1 then
Response.Write "<p>Question 2 correct. The planet with a distinctive ring
system is Saturn.</p>"
Else
Response.Write "<p>Your answer to Question 2: " & Session
("Answer_2") & ". Correct answer: The planet with a distinctive ring
system is Saturn.</p>"
End if
If Session ("Question3") = 1 then
Response.Write "<p>Question 3 correct. The planet with life is
Earth.</p>"
Else
Response.Write "<p>Your answer to Question 3: " & Session
("Answer_3") & ". Correct answer: The planet with life is
Earth.</p>"
End if
If Session ("Question4") = 1 then
Response.Write "<p>Question 4 correct. Image of Earth.</p>"
Else
Response.Write "<p>Your answer to Question 4: " & Session
("Answer_4") & ". Correct answer: (image of) Earth.</p>"
End if
If Session ("Question5") = 1 then
Response.Write "<p>Question 5 correct. Image of Jupiter.</p>"
Else
Response.Write "<p>Your answer to Question 5: " & Session
("Answer_5") & ". Correct answer: (image of) Jupiter.</p>"
End if
If Session ("Question6") = 1 then
Response.Write "<p>Question 6 correct. Image of Saturn.</p>"
Else
Response.Write "<p>Your answer to Question 6: " & Session
("Answer_6") & ". Correct answer: (image of) Saturn.</p>"
End if
Response.Write "<p>Your Score: " & Session ("Correct") &
" correct out of 6.</p>"
Session.Abandon ends the session. If this is not included, the Quiz
will not refresh properly when the browser refresh button is clicked.
%> end of fourth section of script
now comes remainder of HTML code for Quiz Results page
<p><a href="solarquiz.asp">Take Quiz Again</a></p>
<p><a href="solarquizcode.htm">Active Server Page code for this
quiz</a></p>
<p><a href="http://www1.jcu.edu/language/lessons/lessons.htm">Return
to Lessons Page</a></p>
</font>
</font>
</td>
</tr>
</table>
</center></div>
</body>
</html> end of HTML code for Quiz Results page
<% last section of script
End if
%> last line of code for active server page