1. Home
  2. Computing & Technology
  3. JavaScript

Quiz Maker 3 Script

1. Question Body Script

The quiz Javascript on this page processes multiple choice quizes having four possible answers to each question one of which is obviously the correct answer and the other three being wrong. You can have as many questions in the quiz as you require subject only to the length of time that it will take to load the resulting web page.

This version of the script has all of the questions asked via one page and allows you to create separate answer pages for each correct answer. The answer pages will all contain a script that will return to the question page to ask the next question. The version on this page only displays the correct answer page when a correct answer is entered. An alternate version of this body script can be directly substituted to display the correct answer page after every question even when an incorrect answer was selected.

At the end of the quiz a final button will bring up an alert advising the total number of answers that were correct.

Although quizes are just for fun, it spoils the fun somewhat if it is possible to cheat. You will notice when you generate your quiz questions using the quiz generator that there is no single field identifying the correct answer that people will see if they view your page source. Instead there are two apparently random numbers associated with each entry that the script is able to use to work out the right answer when marking each question.

Query strings are used to pass the current question number and number of correct answers so far between pages. The number of correct answers is concealed so as to reduce the possibility of cheating.

The first step in using this script is to select the code from the text box below (there is a highlight all button beneath it to make this easier) and copy it into a file called quizbody.js.

You then link this code into the body of your page where you want the script to appear using the following code:

<script src="quizbody.js"
type="text/javascript">
</script><noscript><table align="center"
cellpadding="3" width="350" border="1"><tr>
<td align="left"><div><b>This Quiz requires Javascript</b>
</div><blockquote>You either have Javascript disabled
<br />or the browser you are using does not<br />
support Javascript. Please use a Javascript<br />
enabled browser to access this quiz.<br />&nbsp;<br />
</blockquote></td></tr></table></noscript>

If you prefer to have the correct answer page appear after each question regardless of whether or not the question has been correctly answered then you can do so by substituting an alternate body script for the one on this page.

Now that you have installed the body script the next step is to create an array of questions and answers to display for the quiz to put in your own unique head script.

Question Body Script | Alternate Question Body Script | Question Head Script | Answer Head Script
Explore JavaScript
About.com Special Features

Stay connected and entertained with reviews on tips on the latest HDTVs, cellphones and more. More >

Easy ways to connect two computers for networking purposes. More >

  1. Home
  2. Computing & Technology
  3. JavaScript

©2009 About.com, a part of The New York Times Company.

All rights reserved.