1. Home
  2. Computing & Technology
  3. JavaScript

Multiple Personality Quiz

3. Results Pages

Now that we haver created our personality quiz, all that remains to be done is to create our fifteen separate results pages. There is no actual Javascript required for these fifteen pages, all we actually need to do is to make sure that we create the pages with the right names for the script to call based on the selections within the quiz. The only limitation on the result pages is that they must all be in the same folder (directory), use the same prefix on all of the file names, and have the rest of the file names match that generated by the quiz.

When we set up the quiz we supplied a prefix for the results page name (it is the value assigned to analPage in the pquizhead.js script if you need to change it). For the purposes of this discussion let's assume that we used a prefix of quizresult (just substitute your actual prefix whereever I mention quizresult in the following discussion).

So let's consider what our fifteen results pages will be. Here is a list of the fifteen pages that we need to create (based on our prefix of quizresult).

  • quizresulta.htm
  • quizresultb.htm
  • quizresultc.htm
  • quizresultd.htm
  • quizresultab.htm
  • quizresultac.htm
  • quizresultad.htm
  • quizresultbc.htm
  • quizresultbd.htm
  • quizresultcd.htm
  • quizresultabc.htm
  • quizresultabd.htm
  • quizresultacd.htm
  • quizresultbcd.htm
  • quizresultabcd.htm

The first four of these pages are the ones that will display if the majority of answers (over 50%) belong to just one personality. The next six (with two letters after the prefix) are the ones that will display if no personality has a majority but where two personalities predominate (make up over 75%) of the answers. The following four (with three letters after the prefix) are those that will display if the answers are reasonably evenly split between three personalities but with only a small response for the fourth (less than 13%). The final results page (with all four letters) will display if the results are too even to satisfy any of the prior conditions.

If you left the fourth "personality" answers blank then only seven result pages will be required as those ending in d.htm will never be called.

If you find that this exact split as to when to display which of the results pages doesn't quite satisfy you then you can change the percentages assigned to the variables one, two, and three at the top of the body script to require a higher percentage match before a given page is displayed. This will increase the likelyhood of pages lower down the list being displayed and reduce the chance of pages higher up the list being displayed. If you increase any of the values above 100 then the corresponding pages will never display and need not be created (eg. if you set two = 101 then the pages with two letters after the prefix are no longer required).

The quiz script generator assumes that the results pages will be in the same folder (directory) as the quiz pages. If this is not the case then all you need to do is to add the appropriate path to the front of the analPage field in the head script to point to the folder where the result pages can be found.

Quiz Head Script | Quiz Body Script | Results Page

Explore JavaScript

More from About.com

  1. Home
  2. Computing & Technology
  3. JavaScript

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

All rights reserved.