| You are here: | About>Computing & Technology>JavaScript> Script Makers> Quiz Scripts> Single Personality Quiz |
![]() | JavaScript |
Single Personality Quiz1. Quiz Head ScriptJoin the DiscussionMore of this FeatureThis quiz has no right and wrong answers. Instead each answer belongs to one of four different "personalities". A separate count of the number of answers selected for each "personality" will be kept and at the end one of six different results pages will be displayed depending on which "personality" gets the most answers (if you want a personality quiz that allows mixed results see the Multiple Personality Quiz). To create the script you must first enter the questions and answers for your quiz into the form below. Once you have entered a question and up to six alternative answers then select the "Add Question" button. If you only require three, four, or five "personalities" for your quiz then leave the extra answers to each question blank. Continue adding as many questions and answers as you require. You can add as many as you like but if you add too many then your quiz page may take a long time to load. The script will display the questions you enter one at a time. When an answer is selected and the "Next Question" button pressed the "personality" associated with the selected answer will be incremented and the encrypted totals passed to the next question. While you enter the answers in a particular order when setting up the quiz, when the questions are actually displayed the answers will be listed in a random order so that which answer belongs to which "personality" will not be obvious unless the person views the quiz source. At the end of the quiz the total for each personality will be evaluated to determine which personality has the highest count. In the event of a tie for most answers one of the tied personalities will be selected at random. The script code for the quiz will appear in the text box below with an additional statement being added for each question you add. Don't worry if you make a mistake as you can always delete lines from the resulting code if you want to remove questions. If you decide you want to start over, simply refresh the current page. Note that the six results pages have a fixed prefix that you enter and then the rest of the filename for the page is generated by the script. If you are setting up additional personality quizes simply give them a different prefix (and save the head scripts to different names). Once you have finished entering your questions and answers, copy the code from the above text box and save it as a file called pquizhead.js. You can rearrange the lines if you want to change the order of the questions or delete lines to remove questions you decide not to include. The only limitations are that you cannot change the first line of the code and you must have at least one question for the quiz script to work. You now add this quiz to the head section of the page where the quiz is to appear using the following code:
<script src="pquizhead.js"
type="text/javascript">
</script> If you are creating more than one quiz then you can use different names for the files where you save the quizes as long as they end in .js and that you modify the code going into the head of the individual quiz pages to reference the appropriate quiz files you have created as well as using a different prefix for the results pages. So now that we have created the questions and answers the next step is to obtain the body script that will display them on your page.
Quiz Head Script | Quiz Body
Script | Results Pages
|
|
All Topics | Email Article | | | ![]() |
| Advertising Info | News & Events | Work at About | SiteMap | Reprints | Help | Our Story | Be a Guide |
| User Agreement | Ethics Policy | Patent Info. | Privacy Policy | ©2008 About, Inc., A part of The New York Times Company. All rights reserved. |


