/    Sign up×
Community /Pin to ProfileBookmark

Javascript Personality Quiz help

Hi, I’m currently a student at the International School of Beijing. I’m taking a computer connectivity course and I’m trying to make a personality quiz that is a series of multiple choice questions. Each answer is worth a certain amount of points and at the end all the points are added up and a personality type opens in a new window. Nothing is working though and I really really really need help!!! PLEASE!!! The script is below:

<HTML>
<HEAD>
<TITLE>
Personality Quiz
</TITLE>
<script language=”javascript”>

var Quest = new Array(10);
//this sets up an array for all of the answers that are given

function populate(){
alert(“function populate started”);
//this function gives each of the answers 0 points so if someone doesnt answer a question the whole thing will continue to work
for(i=0; i<10; i++){
Quest[i]=0;
}
}

function total(){
alert(“function total started”);
//this function adds the number of points each answer is worth together
int myScore=0;
for(int i=0, i<10; i++){
myScore=myScore+Quest[i];
}
analyzer (myScore)
}

function analyzer (myScore){
//this function uses the total calculated score to figure out which personality type they are
if(myScore>60){
myContents = “Others see you as someone they should handle with care Youre seen as vain, self centered, and who is extremely dominant. Others may admire you, wishing they could be more like you, but dont always trust you, hesitating to become too deeply involved with you.”
}
else if(myScore>50 && myScore<61){
myContents = “Others see you as an exciting, highly volatile, rather impulsive personality; a natural leader, whos quick to make decisions, though not always the right ones. They see you as bold and adventuresome, someone who will try anything once; someone who takes chances and enjoys an adventure. They enjoy being in your company because of the excitement you radiate.”
}
else if(myScore>40 && myScore<51){
myContents = “Others see you as fresh, lively, charming, amuzing, practical, and always interesting; someone whos constantly in the center of attention, but sufficiently well balanced not to let it go their head. They also see you as kind, considerate, and understanding; someone who will always cheer them up and help them out.”
}
else if(myScore>30 &&myScore<41){
myContents = “Others see you as sensible, cautious, careful and practical. They see you as clever, gifted, or talented, but modest…Not a person who makes friends too quickly or easily, but someone whos extremely loyal to friends you do make and who expect the same loyalty in return. Those who really get to know you realize it takes a lot to shake your trust in yoru friends, but eqally that it takes you a long time to get over it if that trust is ever broken.”
}
else if(myScore>20 && myScore<31){
myContents = “Your friends see you as painstaking and fussy. They see you as very cautious, extremely careful, a slow and steay plodder. It would really suprise them if you ever did something impulsively or on the spur of the moment, expecting you to examine everything carefully from every angle and then, usally against it. They think this reaction is caused partly by your careful nature.”
}
else if(myScore<21){
myContents = “People think you are shy, nervous, and indecisive, someone who needs looking after, who always wants someone else to make the decisions and who does not want to get involved with anyone or anything. THey see you as a worrier who always sees problems that dont exist. SOme people think you are boring. Only those who know you well know that you are not.”
}
myDisplay(myContents)
}

function myDisplay(myContents){
//This function will open a new window and show the results calculated
alert(myContents)

}

function saver(int q, int points)
//this function puts the points that each answer is worth into the array
{
q=q-1;
Quest[q]=points
}

</script>
<style type=”text/css”>
<!–
.style1 {
font-family: Verdana, Arial, Helvetica, sans-serif;
font-weight: bold;
font-size: 24px;
color: #FF0080;
}
.style2 {font-family: Arial, Helvetica, sans-serif}
.style3 {color: #FF0080}
.style5 {color: #00FF00}
.style6 {color: #0080FF}
.style11 {color: #80FFFF}
–>
</style>
</HEAD>

<BODY onLoad=”populate()”>
<FORM NAME=”personalityForm”>
<span class=”style1″>Personality Quiz</span><br>
<br>

<span class=”style2″><span class=”style3″>1. When do you feel your best?</span><br>
<INPUT TYPE=”RADIO” NAME=”q1″ checked onClick=”saver(1,2)”>
<span class=”style6″>in the morning<br>
<INPUT TYPE=”RADIO” NAME=”q1″ onClick=”saver(1,4)”>
during the afternoon & early evening<br>
<INPUT TYPE=”RADIO” NAME=”q1″ onClick=”saver(1,6)”>
late at night</span><br>
<br>

<span class=”style3″>2. You usually walk</span><br>
<span class=”style6″>
<INPUT TYPE=”RADIO” NAME=”q2″ onClick=”saver(2,6)” >
fairly fast, with long steps<br>
<INPUT TYPE=”RADIO” NAME=”q2″ onClick=”saver(2,4)”>
fairly fast, with short, quick steps<br>
<INPUT TYPE=”RADIO” NAME=”q2″ onClick=”saver(2,7)”>
less fast head up, looking the world in the face<br>
<INPUT TYPE=”RADIO” NAME=”q2″ onClick=”saver(2,2)”>
less fast, head down<br>
<INPUT TYPE=”RADIO” NAME=”q2″ onClick=”saver(2,1)”>
very slowly<br>
</span><br>

<span class=”style3″>3.When talking to people you</span><br>
<INPUT TYPE=”RADIO” NAME=”q3″ onClick=”saver(3,4)”>
<span class=”style6″>stand with your arms folder<br>
<INPUT TYPE=”RADIO” NAME=”q3″ onClick=”saver(3,2)”>
have your hands clasped<br>
<INPUT TYPE=”RADIO” NAME=”q3″ onClick=”saver(3,5)”>
have one or both your hands on your hips<br>
<INPUT TYPE=”RADIO” NAME=”q3″ onClick=”saver(3,7)”>
touch or push the person to whom you are talking<br>
<INPUT TYPE=”RADIO” NAME=”q3″ onClick=”saver(3,6)”>
play with your ear, touch your chin, or smooth
your hair</span><br>
<br>

<span class=”style3″>4. When relaxing, you sit with</span><br>
<span class=”style6″>
<INPUT TYPE=”RADIO” NAME=”q4″ onClick=”saver(4,4)”>
your knees bent with your legs neatly side by side<br>
<INPUT TYPE=”RADIO” NAME=”q4″ onClick=”saver(4,6)”>
your legs crossed<br>
<INPUT TYPE=”RADIO” NAME=”q4″ onClick=”saver(4,2)”>
your legs stretched out or straight<br>
<INPUT TYPE=”RADIO” NAME=”q4″ onClick=”saver(4,1)”>
one leg curled under you</span><br>
<br>

<span class=”style3″>5. When something really amuses you, you react with</span><br>
<INPUT TYPE=”RADIO” NAME=”q5″ onClick=”saver(5,6)”>
<span class=”style6″> a big, appreciative laugh<br>
<INPUT TYPE=”RADIO” NAME=”q5″ onClick=”saver(5,4)”>
a laugh, but not a loud one<br>
<INPUT TYPE=”RADIO” NAME=”q5″ onClick=”saver(5,3)”>
a quiet chuckle<br>
<INPUT TYPE=”RADIO” NAME=”q5″ onClick=”saver(5,5)”>
a sheepish smile</span><br>
<span class=”style5″><br>

<span class=”style3″>6. When you go to a party or social gathering you</span></span><br>
<span class=”style6″>
<INPUT TYPE=”RADIO” NAME=”q6″ onClick=”saver(6,6)”>
make a loud entrance so everyone notices you<br>
<INPUT TYPE=”RADIO” NAME=”q6″ onClick=”saver(6,4)”>
make a quiet entrance, looking around for someone you know<br>
<INPUT TYPE=”RADIO” NAME=”q6″ onClick=”saver(6,2)”>
make the quietest entrance, trying to stay unnoticed</span><br>
<span class=”style3″><br>

7.You’re working very hard, concentrating hard, and you’re interrupted. Do you..</span><br>
<INPUT TYPE=”RADIO” NAME=”q7″ onClick=”saver(7,6)”>
<span class=”style6″>welcome the break<br>
<INPUT TYPE=”RADIO” NAME=”q7″ onClick=”saver(7,2)”>
feel extremely irritated<br>
<INPUT TYPE=”RADIO” NAME=”q7″ onClick=”saver(7,4)”>
vary between these two extremes</span><br>
<br>

<span class=”style3″>8. Which of the following colors do you like most?</span><br>
<INPUT TYPE=”RADIO” NAME=”q8″ onClick=”saver(8,6)” >
<span class=”style6″> red or orange<br>
<INPUT TYPE=”RADIO” NAME=”q8″ onClick=”saver(8,7)” >
black<br>
<INPUT TYPE=”RADIO” NAME=”q8″ onClick=”saver(8,5)” >
yellow or light blue<br>
<INPUT TYPE=”RADIO” NAME=”q8″ onClick=”saver(8,4)” >
green<br>
<INPUT TYPE=”RADIO” NAME=”q8″ onClick=”saver(8,3)” >
dark blue or purple<br>
<INPUT TYPE=”RADIO” NAME=”q8″ onClick=”saver(8,2)” >
white<br>
<INPUT TYPE=”RADIO” NAME=”q8″ onClick=”saver(8,1)” >
brown or gray</span><br>
<span class=”style3″><br>

  • 9.

    When you are in bed at night, in those last few moments before going to sleep, you lie</span><br>
    <INPUT TYPE=”RADIO” NAME=”q9″ onClick=”saver(9,7)” >
    <span class=”style6″>stretched out on your back<br>
    <INPUT TYPE=”RADIO” NAME=”q9″ onClick=”saver(9,6)” >
    stretched out face down on your stomach<br>
    <INPUT TYPE=”RADIO” NAME=”q9″ onClick=”saver(9,4)” >
    on your side, slightly curled<br>
    <INPUT TYPE=”RADIO” NAME=”q9″ onClick=”saver(9,2)” >
    with your head on one arm<br>
    <INPUT TYPE=”RADIO” NAME=”q9″ onClick=”saver(9,1)” >
    with your head under the covers</span><br>
    <span class=”style3″><br>

  • 10.

    You often dream that you are</span><br>
    <INPUT TYPE=”RADIO” NAME=”q10″ onClick=”saver(10,4)” >
    <span class=”style6″>falling<br>
    <INPUT TYPE=”RADIO” NAME=”q10″ onClick=”saver(10,2)” >
    fighting or struggling<br>

  • <INPUT TYPE=”RADIO” NAME=”q10″ onClick=”saver(10,3)” >
    searching for something or somebody<br>
    <INPUT TYPE=”RADIO” NAME=”q10″ onClick=”saver(10,5)” >
    flying or floating<br>
    <INPUT TYPE=”RADIO” NAME=”q10″ onClick=”saver(10,6)” >
    you usually have dreamless sleep<br>
    <INPUT TYPE=”RADIO” NAME=”q10″ onClick=”saver(10,1)” >
    your dreams are always pleasant </span><br>

    <br>
    <INPUT TYPE=”button” NAME=”result” Value=”Click here to see your result” onClick=”total()”>
    </span>
    </FORM>
    </BODY>
    </HTML>

    PLEASE HELP!!! THanks!!

    to post a comment
    JavaScript

    1 Comments(s)

    Copy linkTweet thisAlerts:
    @JMRKERMay 04.2007 — You had several syntax errors showing up in the error console.

    One main one was the use of 'int'. This is a special word for 'java' not JS.

    There were several <span> tags that didn't match up.

    I tidied up the script a bit so that I could understand it better.

    Primary thing was to seperate content from function; ie, 'myContents' and new pointer to array 'myContentsPtr'

    While I don't know if the quiz is correct, here's my take on your code.

    [code=php]
    <HTML>
    <HEAD>
    <TITLE>Personality Quiz</TITLE>
    <script language="javascript">

    var Quest = new Array(10); //this sets up an array for all of the answers that are given

    function populate() {
    // alert("function populate started");
    // this function gives each of the answers 0 points so if someone doesn't answer a question
    // the whole thing will continue to work
    for(var i=0; i<10; i++) { Quest[i]=0; }
    }

    function total() {
    // alert("function total started");
    // this function adds the number of points each answer is worth together
    myScore=0;
    for (var i=0; i<10; i++) { myScore=myScore+Quest[i]; }
    analyzer(myScore);
    }
    myContents = new Array();
    myContents[0] = "Others see you as someone they should handle with care You're seen as vain, self centered,"
    + " and who is extremely dominant. Others may admire you, wishing they could be more like you, but don't always trust you,"
    + " hesitating to become too deeply involved with you.";
    myContents[1] = "Others see you as an exciting, highly volatile, rather impulsive personality; a natural leader,"
    + " who's quick to make decisions, though not always the right ones. They see you as bold and adventuresome,"
    + " someone who will try anything once; someone who takes chances and enjoys an adventure."
    + " They enjoy being in your company because of the excitement you radiate.";
    myContents[2] = "Others see you as fresh, lively, charming, amuzing, practical, and always interesting;"
    + " someone who's constantly in the center of attention, but sufficiently well balanced not to let it go their head."
    + " They also see you as kind, considerate, and understanding; someone who will always cheer them up and help them out.";
    myContents[3] = "Others see you as sensible, cautious, careful and practical. They see you as clever, gifted,"
    + " or talented, but modest...Not a person who makes friends too quickly or easily, but someone who's extremely loyal"
    + " to friends you do make and who expect the same loyalty in return. Those who really get to know you realize"
    + " it takes a lot to shake your trust in yoru friends, but eqally that it takes you a long time to get over it"
    + " if that trust is ever broken.";
    myContents[4] = "Your friends see you as painstaking and fussy. They see you as very cautious, extremely careful,"
    + " a slow and steay plodder. It would really suprise them if you ever did something impulsively or on the spur"
    + " of the moment, expecting you to examine everything carefully from every angle and then, usally against it."
    + " They think this reaction is caused partly by your careful nature.";
    myContents[5] = "People think you are shy, nervous, and indecisive, someone who needs looking after,"
    + " who always wants someone else to make the decisions and who does not want to get involved with anyone or anything."
    + " They see you as a worrier who always sees problems that dont exist. SOme people think you are boring."
    + " Only those who know you well know that you are not."

    function analyzer (myScore) {
    // this function uses the total calculated score to figure out which personality type they are
    if (myScore>60) { myContentsPtr = 0; }
    else { if (myScore > 50) { myContentsPtr = 1; }
    else { if(myScore>40) { myContentsPtr = 2; }
    else { if(myScore>30) { myContentsPtr = 3; }
    else { if(myScore>20) { myContentsPtr = 4; }
    else { myContentsPtr = 5; }
    }
    }
    }
    }
    myDisplay(myContents[myContentsPtr])
    }

    function myDisplay(myContents) {
    //This function will open a new window and show the results calculated
    alert(myContents);
    }

    function saver(q, points) {
    // this function puts the points that each answer is worth into the array
    q=q-1;
    Quest[q]=points
    }

    </script>
    <style type="text/css">
    .style1 {
    font-family: Verdana, Arial, Helvetica, sans-serif;
    font-weight: bold;
    font-size: 24px;
    color: #FF0080;
    }
    .style2 {font-family: Arial, Helvetica, sans-serif}
    .style3 {color: #FF0080}
    .style5 {color: #00FF00}
    .style6 {color: #0080FF}
    .style11 {color: #80FFFF}
    </style>
    </HEAD>

    <BODY onLoad="populate()">
    <FORM NAME="personalityForm">
    <span class="style1">Personality Quiz</span><br>
    <br>

    <span class="style2">

    <span class="style3">1. When do you feel your best?</span><br>
    <span class="style6">
    <INPUT TYPE="RADIO" NAME="q1" onClick="saver(1,2)">in the morning<br>
    <INPUT TYPE="RADIO" NAME="q1" onClick="saver(1,4)">during the afternoon & early evening<br>
    <INPUT TYPE="RADIO" NAME="q1" onClick="saver(1,6)">late at night<br>
    </span><br>

    <span class="style3">2. You usually walk</span><br>
    <span class="style6">
    <INPUT TYPE="RADIO" NAME="q2" onClick="saver(2,6)" >fairly fast, with long steps<br>
    <INPUT TYPE="RADIO" NAME="q2" onClick="saver(2,4)">fairly fast, with short, quick steps<br>
    <INPUT TYPE="RADIO" NAME="q2" onClick="saver(2,7)">less fast head up, looking the world in the face<br>
    <INPUT TYPE="RADIO" NAME="q2" onClick="saver(2,2)">less fast, head down<br>
    <INPUT TYPE="RADIO" NAME="q2" onClick="saver(2,1)">very slowly<br>
    </span><br>

    <span class="style3">3.When talking to people you</span><br>
    <span class="style6">
    <INPUT TYPE="RADIO" NAME="q3" onClick="saver(3,4)">stand with your arms folder<br>
    <INPUT TYPE="RADIO" NAME="q3" onClick="saver(3,2)">have your hands clasped<br>
    <INPUT TYPE="RADIO" NAME="q3" onClick="saver(3,5)">have one or both your hands on your hips<br>
    <INPUT TYPE="RADIO" NAME="q3" onClick="saver(3,7)">touch or push the person to whom you are talking<br>
    <INPUT TYPE="RADIO" NAME="q3" onClick="saver(3,6)">play with your ear, touch your chin, or smooth your hair<br>
    </span><br>

    <span class="style3">4. When relaxing, you sit with</span><br>
    <span class="style6">
    <INPUT TYPE="RADIO" NAME="q4" onClick="saver(4,4)">your knees bent with your legs neatly side by side<br>
    <INPUT TYPE="RADIO" NAME="q4" onClick="saver(4,6)">your legs crossed<br>
    <INPUT TYPE="RADIO" NAME="q4" onClick="saver(4,2)">your legs stretched out or straight<br>
    <INPUT TYPE="RADIO" NAME="q4" onClick="saver(4,1)">one leg curled under you<br>
    </span><br>

    <span class="style3">5. When something really amuses you, you react with</span><br>
    <span class="style6">
    <INPUT TYPE="RADIO" NAME="q5" onClick="saver(5,6)">a big, appreciative laugh<br>
    <INPUT TYPE="RADIO" NAME="q5" onClick="saver(5,4)">a laugh, but not a loud one<br>
    <INPUT TYPE="RADIO" NAME="q5" onClick="saver(5,3)">a quiet chuckle<br>
    <INPUT TYPE="RADIO" NAME="q5" onClick="saver(5,5)">a sheepish smile<br>
    </span><br>

    <span class="style3">6. When you go to a party or social gathering you</span><br>
    <span class="style6">
    <INPUT TYPE="RADIO" NAME="q6" onClick="saver(6,6)">make a loud entrance so everyone notices you<br>
    <INPUT TYPE="RADIO" NAME="q6" onClick="saver(6,4)">make a quiet entrance, looking around for someone you know<br>
    <INPUT TYPE="RADIO" NAME="q6" onClick="saver(6,2)">make the quietest entrance, trying to stay unnoticed<br>
    </span><br>

    <span class="style3"><br>7.You're working very hard, concentrating hard, and you're interrupted. Do you..</span><br>
    <span class="style6">
    <INPUT TYPE="RADIO" NAME="q7" onClick="saver(7,6)">welcome the break<br>
    <INPUT TYPE="RADIO" NAME="q7" onClick="saver(7,2)">feel extremely irritated<br>
    <INPUT TYPE="RADIO" NAME="q7" onClick="saver(7,4)">vary between these two extremes<br>
    </span><br>

    <span class="style3">8. Which of the following colors do you like most?</span><br>
    <span class="style6">
    <INPUT TYPE="RADIO" NAME="q8" onClick="saver(8,6)" >red or orange<br>
    <INPUT TYPE="RADIO" NAME="q8" onClick="saver(8,7)" >black<br>
    <INPUT TYPE="RADIO" NAME="q8" onClick="saver(8,5)" >yellow or light blue<br>
    <INPUT TYPE="RADIO" NAME="q8" onClick="saver(8,4)" >green<br>
    <INPUT TYPE="RADIO" NAME="q8" onClick="saver(8,3)" >dark blue or purple<br>
    <INPUT TYPE="RADIO" NAME="q8" onClick="saver(8,2)" >white<br>
    <INPUT TYPE="RADIO" NAME="q8" onClick="saver(8,1)" >brown or gray<br>
    </span><br>

    <span class="style3">9. When you are in bed at night, in those last few moments before going to sleep, you lie</span><br>
    <span class="style6">
    <INPUT TYPE="RADIO" NAME="q9" onClick="saver(9,7)" >stretched out on your back<br>
    <INPUT TYPE="RADIO" NAME="q9" onClick="saver(9,6)" >stretched out face down on your stomach<br>
    <INPUT TYPE="RADIO" NAME="q9" onClick="saver(9,4)" >on your side, slightly curled<br>
    <INPUT TYPE="RADIO" NAME="q9" onClick="saver(9,2)" >with your head on one arm<br>
    <INPUT TYPE="RADIO" NAME="q9" onClick="saver(9,1)" >with your head under the covers<br>
    </span><br>

    <span class="style3"><br>10. You often dream that you are</span><br>
    <span class="style6">
    <INPUT TYPE="RADIO" NAME="q10" onClick="saver(10,4)" >falling<br>
    <INPUT TYPE="RADIO" NAME="q10" onClick="saver(10,2)" >fighting or struggling<br>
    <INPUT TYPE="RADIO" NAME="q10" onClick="saver(10,3)" >searching for something or somebody<br>
    <INPUT TYPE="RADIO" NAME="q10" onClick="saver(10,5)" >flying or floating<br>
    <INPUT TYPE="RADIO" NAME="q10" onClick="saver(10,6)" >you usually have dreamless sleep<br>
    <INPUT TYPE="RADIO" NAME="q10" onClick="saver(10,1)" >your dreams are always pleasant.<br>
    </span><br>

    <br>
    <INPUT TYPE="button" NAME="result" Value="Click here to see your result" onClick="total()">
    <span>

    </FORM>
    </BODY>
    </HTML>
    [/code]


    Not bad for a first attempt.
    ×

    Success!

    Help @awood1021 spread the word by sharing this article on Twitter...

    Tweet This
    Sign in
    Forgot password?
    Sign in with TwitchSign in with GithubCreate Account
    about: ({
    version: 0.1.9 BETA 6.17,
    whats_new: community page,
    up_next: more Davinci•003 tasks,
    coming_soon: events calendar,
    social: @webDeveloperHQ
    });

    legal: ({
    terms: of use,
    privacy: policy
    });
    changelog: (
    version: 0.1.9,
    notes: added community page

    version: 0.1.8,
    notes: added Davinci•003

    version: 0.1.7,
    notes: upvote answers to bounties

    version: 0.1.6,
    notes: article editor refresh
    )...
    recent_tips: (
    tipper: @nearjob,
    tipped: article
    amount: 1000 SATS,

    tipper: @meenaratha,
    tipped: article
    amount: 1000 SATS,

    tipper: @meenaratha,
    tipped: article
    amount: 1000 SATS,
    )...