JavaScript

  1. Home
  2. Computing & Technology
  3. JavaScript

Amending Quizes

Introduction

If you are using one of the quz scripts from this site then there may come a time when you want to change something in the quiz. When that time comes, you don't need to create the quiz all over again.

Many of the changes that you may wish to make can be easily made by directly editing the quiz file. Other changes require that you use the quiz maker to generate the code for new/changed questions but you can then edit your existing script to incorporate the changes.

On the following pages we will look at how you can make various different types of changes to your quiz.

Changing Question Order or Deleting Questions

You can easily change the order of the questions in your quiz. Each quiz question along with the answers etc exists as a single entry within the script that starts with quiz[r++] =. Each of these is on a separate line within your script.

To change the order of the questions within the script you simply change the order in which these entries appear within your script. There is nothing in the entries that relates specifically to the order of the questions, the order of the questions is determined by the value of "r" which is incremented by one for each question in the order that they appear in the file (that's what the ++ means.

Similarly, you can delete questions from the quiz simply by deleting the appropriate entry. Alternatively, if you just want to delete a question temporarily you can add // to the front of the entry. This will co0nvert the entry into a comment and it will be ignored by the script. When you are ready to put the question back in you just remove the //

The only thing that you have to watch for is that you need to leave the lines at the top of the quiz above the first entry alone or you may mess up the creation of the array that contains your quiz details.

Changing Questions/Answers/Destination Pages

The exact wording of questions, answers, and destination pages (for those quizes that use them) all appear in the quiz entries in plain text.

If you wish to edit the wording of a question or answer (or change a destination page) then you can simply edit the entry within the script itself to make your changes directly. There are just a couple of things to watch for though when you do this.

  1. You can't change which answer is correct if you change the answers. The information as to which is the correct answer is concealed within the two numbers at the start of each entry.
  2. Any apostrophes within the question or answers needs to be "escaped" by placing a backslash in front of it (\'). Otherwise it will be interpreted as the end of the text and will stop the script working.
  3. You can't include tilde characters (~) in your questions or answers as this character is used by the script as a separator between the parts of an entry.
  4. If you want to display a <, >, or & in a question or answer then you need to code it as &lt;, &gt;, or &amp; respectively so that it is not misinterpreted as HTML.

Adding Questions

To add questions to your quiz you will need to return to the page where you generated the quiz in the first place. You don't need to waste time re-entering all of the questions that you already have in the quiz. Instead just enter your new questions and answers.

Once you have generated the script containing your new questions you can then add the code to the end of your existing quiz script instead of making a new one. You then just delete those lines of code between the last of the previously existing questions and the first of the new ones since a copy of those lines already exists at the top of the script and a second copy is not required.

You can then reorder the questions to move the new questions to whereever you want them to be in the question order.

Changing Which Answer is Correct

Since the information as to which answer is correct is concealed in the two numbers on the front of the entry you cannot directly edit the entry to change which answer s the correct one.

If you want to rearrange the answers to a quiz question then the quickest way is to return to the page where you created the quiz in the first place and re-enter the question there with your answers in the new order. Once you have created a new entry for the question you can extract it from the new script and insert it into your existing script in place of the old version of the question.

Explore JavaScript

About.com Special Features

JavaScript

  1. Home
  2. Computing & Technology
  3. JavaScript

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

All rights reserved.