www.webdeveloper.com
Recent Articles
  • Finding Slow Running Queries in ASE 15
  • A More Advanced Pie Chart for Analysis Services Data
  • Adobe AIR Programming Unleashed: Working with Windows
  • Performance Testing SQL Server 2008's Change Data Capture Functionality
  • The ABC's of PHP: Introduction to PHP
  • How to Migrate from BasicFiles to SecureFiles Storage
  • Why the Twitter Haters Are Wrong
  • User Personalization with PHP: Beginning the Application
  • Whats in an Oracle Schema?
  • Lighting Enhancement in Photoshop
  •  

    Go Back   WebDeveloper.com > Client-Side Development > JavaScript

    JavaScript JavaScript (not Java) Discussion and technical support, including AJAX and frameworks (JQuery, MooTools, Prototype...)

    Reply
     
    Thread Tools Search this Thread Rate Thread Display Modes
      #1  
    Old 05-05-2005, 04:47 PM
    needhelp1234 needhelp1234 is offline
    Registered User
     
    Join Date: May 2005
    Posts: 31
    Question URGENT-HELP!!! I dont understand whtas rong with this CODE

    Please fix this code so it displays the score at the bottom . I dont know how to or what to do, PLease i tried for hours i really need this urgently.
    <SCRIPT LANGUAGE="JavaScript">
    <!--

    var question = new Array(); var answer = new Array(); var correctAnswer = new Array(); var userAnswer = new Array();
    question[1] = "What comedian had just started a new TV series, playing a mailman on "The Royal Family," when he died of a heart attack in 1991?"
    correctAnswer[1] = "E"
    userAnswer[1] = ""
    answer[1] = "Bill Macy"
    answer[2] = "James Coco"
    answer[3] = "Gabriel Kaplan"
    answer[4] = "Charles Ruggles"
    answer[5] = "Redd Foxx"
    question[2] = "Who was Fred Astaire's dance partner in the movie musical "Royal Wedding?""
    correctAnswer[2] = "A"
    userAnswer[2] = ""
    answer[6] = "Jane Powell"
    answer[7] = "Cyd Charisse"
    answer[8] = "Judy Garland"
    answer[9] = "Kim Hunter"
    answer[10] = "Cathy Rigby"
    question[3] = "What golfer won consecutive British Opens at Royal Troon in 1982 and Royal Birkdale in 1983?"
    correctAnswer[3] = "D"
    userAnswer[3] = ""
    answer[11] = "Wayne Grady"
    answer[12] = "Nick Faldo"
    answer[13] = "Payne Stewart"
    answer[14] = "Tom Watson"
    answer[15] = "Jack Nicklaus"
    question[4] = "What golden insect sits on top of the Royal Exchange in London?"
    correctAnswer[4] = "A"
    userAnswer[4] = ""
    answer[16] = "Grasshopper"
    answer[17] = "Mantis"
    answer[18] = "Ant"
    answer[19] = "Wasp"
    answer[20] = "Mosquito"
    question[5] = "The Royal Gorge Bridge is the highest suspension bridge in the United States. In which U.S. state is it located?"
    correctAnswer[5] = "E"
    userAnswer[5] = ""
    answer[21] = "California"
    answer[22] = "Texas"
    answer[23] = "Montana"
    answer[24] = "New York"
    answer[25] = "Colorado"
    question[6] = "What is the official slogan of the Royal Canadian Mounted Police?"
    correctAnswer[6] = "B"
    userAnswer[6] = ""
    answer[26] = ""We always get our man""
    answer[27] = ""Maintain the right""
    answer[28] = ""We are family""
    answer[29] = ""Be vigilant""
    answer[30] = ""One Mountie, one riot""
    question[7] = "What comic strip character was the subject of a top ten novelty hit for the Royal Guardsmen in 1966?"
    correctAnswer[7] = "D"
    userAnswer[7] = ""
    answer[31] = "Popeye"
    answer[32] = "Beetle Bailey"
    answer[33] = "Alley Oop"
    answer[34] = "Snoopy"
    answer[35] = "Little Orphan Annie"
    question[8] = "How many lines of verse occur in the stanza form known as "rhyme royal"?"
    correctAnswer[8] = "C"
    userAnswer[8] = ""
    answer[36] = "4"
    answer[37] = "5"
    answer[38] = "7"
    answer[39] = "14"
    answer[40] = "16"

    function displayResults()
    {
    userAnswer[1] = document.answers.Question1.value;
    userAnswer[2] = document.answers.Question2.value;
    userAnswer[3] = document.answers.Question3.value;
    userAnswer[4] = document.answers.Question4.value;
    userAnswer[5] = document.answers.Question5.value;
    userAnswer[6] = document.answers.Question6.value;
    userAnswer[7] = document.answers.Question7.value;
    userAnswer[8] = document.answers.Question8.value;

    var correctIncorrect1;
    var correctIncorrect2;
    var correctIncorrect3;
    var correctIncorrect4;
    var correctIncorrect5;
    var correctIncorrect6;
    var correctIncorrect7;
    var correctIncorrect8;

    if (userAnswer[1] == correctAnswer[1])
    {
    correctIncorrect1 = "correct";
    }
    else
    {
    correctIncorrect1= "incorrect";
    }
    if (userAnswer[2] == correctAnswer[2])
    {
    correctIncorrect2 = "correct";
    }
    else
    {
    correctIncorrect2 = "incorrect";
    }
    if (userAnswer[3] == correctAnswer[3])
    {
    correctIncorrect3 = "correct";
    }
    else
    {
    correctIncorrect3 = "incorrect";
    }
    if (userAnswer[4] == correctAnswer[4])
    {
    correctIncorrect4 = "correct";
    }
    else
    {
    correctIncorrect4 = "incorrect";
    }
    if (userAnswer[5] == correctAnswer[5])
    {
    correctIncorrect5 = "correct";
    }
    else
    {
    correctIncorrect5 = "incorrect";
    }
    if (userAnswer[6] == correctAnswer[6])
    {
    correctIncorrect6 = "correct";
    }
    else
    {
    correctIncorrect6 = "incorrect";
    }
    if (userAnswer[7] == correctAnswer[7])
    {
    correctIncorrect7 = "correct";
    }
    else
    {
    correctIncorrect7 = "incorrect";
    }
    if (userAnswer[8] == correctAnswer[8])
    {
    correctIncorrect8 = "correct";
    }
    else
    {
    correctIncorrect8 = "incorrect";
    }


    var content="<HTML><HEAD><TITLE>Quiz+
    Results</TITLE></HEAD>"+
    "<BODY><CENTER><H1>Quiz+
    Results</H1></CENTER><P>" +
    "<FONT COLOR='0000FF'><B>" +
    "Question 1 was, "" + question[1] + ""<BR>" + "Your answer was, "" + userAnswer[1] + "."<BR>" +
    "The correct answer was, "" + correctAnswer[1] + "."<BR>" +
    "You were " + correctIncorrect1 + ".<P>" +
    "Question 2 was, "" + question[2] + ""<BR>"
    + "Your answer was, "" + userAnswer[2] + "."<BR>" +
    "The correct answer was, "" + correctAnswer[2] + "."<BR>" +
    "You were " + correctIncorrect2 + ".<P>" +
    "Question 3 was, "" + question[3] + ""<BR>" + "Your answer was, "" + userAnswer[3] + "."<BR>" +
    "The correct answer was, "" + correctAnswer[3] + "."<BR>" +
    "You were " + correctIncorrect3 + ".<P>" +
    "Question 4 was, "" + question[4] + ""<BR>" + "Your answer was, "" + userAnswer[4] + "."<BR>" +
    "The correct answer was, "" + correctAnswer[4] + "."<BR>" +
    "You were " + correctIncorrect4 + ".<P>" +
    "Question 5 was, "" + question[5] + ""<BR>" + "Your answer was, "" + userAnswer[5] + "."<BR>" + "The correct answer was, "" + correctAnswer[5] + "."<BR>" +
    "You were " + correctIncorrect5 + ".<P>" +
    "Question 6 was, "" + question[6] + ""<BR>" + "Your answer was, "" + userAnswer[6] + "."<BR>" + "The correct answer was, "" +
    "" + correctAnswer[6] + "."<BR>" +
    "You were " + correctIncorrect6 + ".<P>" +
    "Question 7 was, "" + question[7] + ""<BR>" + "Your answer was, "" + userAnswer[7] + "."<BR>" + "The correct answer was, "" + correctAnswer[7] + "."<BR>" +
    "You were " + correctIncorrect7 + ".<P>" +
    "Question 8 was, "" + question[8] + ""<BR>" + "Your answer was, "" + userAnswer[8] + "."<BR>" + "The correct answer was, "" + correctAnswer[8] + "."<BR>" +
    "You were " + correctIncorrect8 + ".<P>";
    //Line 202
    document.open();
    document.write(content);
    document.close();
    }

    // -->
    </SCRIPT>
    </HEAD>
    <BODY>
    <CENTER>
    <H2>
    <FONT COLOR="#FF0000">
    Welcome to the JavaScript quiz!
    </FONT>
    </H2>
    </CENTER>
    <P>
    <H3>
    <FORM METHOD=POST NAME="answers">
    1. What comedian had just started a new TV series, playing a mailman on "The Royal Family," when he died of a heart attack in 1991?
    <BR>
    <INPUT TYPE="RADIO" NAME="Question1" VALUE="A" checked> A. Bill Macy
    <BR>
    <INPUT TYPE="RADIO" NAME="Question1" VALUE="B"> B. Cyd Charisse
    <BR>
    <INPUT TYPE="RADIO" NAME="Question1" VALUE="C"> C. Gabriel Kaplan
    <BR>
    <INPUT TYPE="RADIO" NAME="Question1" VALUE="D"> D. Charles Ruggles
    <BR>
    <INPUT TYPE="RADIO" NAME="Question1" VALUE="E"> E. Redd Foxx
    <P>
    2. Who was Fred Astaire's dance partner in the movie musical "Royal Wedding?"
    <BR>
    <INPUT TYPE="RADIO" NAME="Question2" VALUE="A" checked> A. Jane Powell
    <BR>
    <INPUT TYPE="RADIO" NAME="Question2" VALUE="B"> B. Cyd Charisse
    <BR>
    <INPUT TYPE="RADIO" NAME="Question2" VALUE="C"> C. Judy Garland
    <BR>
    <INPUT TYPE="RADIO" NAME="Question2" VALUE="D"> D. Kim Hunter
    <BR>
    <INPUT TYPE="RADIO" NAME="Question2" VALUE="E"> E. Cathy Rigby
    <P>
    3. What golfer won consecutive British Opens at Royal Troon in 1982 and Royal Birkdale in 1983?
    <BR>
    <INPUT TYPE="RADIO" NAME="Question3" VALUE="A" checked> A. Wayne Grady
    <BR>
    <INPUT TYPE="RADIO" NAME="Question3" VALUE="B"> B. Nick Faldo
    <BR>
    <INPUT TYPE="RADIO" NAME="Question3" VALUE="C"> C. Payne Stewart
    <BR>
    <INPUT TYPE="RADIO" NAME="Question3" VALUE="D"> D. Tom Watson
    <BR>
    <INPUT TYPE="RADIO" NAME="Question3" VALUE="E"> E. Jack Nicklaus
    <P>
    4. What golden insect sits on top of the Royal Exchange in London?
    <BR>
    <INPUT TYPE="RADIO" NAME="Question4" VALUE="A" checked> A. Grasshopper
    <BR>
    <INPUT TYPE="RADIO" NAME="Question4" VALUE="B"> B. Mantis
    <BR>
    <INPUT TYPE="RADIO" NAME="Question4" VALUE="C"> C. Ant
    <BR>
    <INPUT TYPE="RADIO" NAME="Question4" VALUE="D"> D. Wasp
    <BR>
    <INPUT TYPE="RADIO" NAME="Question4" VALUE="E"> E. Mosquito
    <P>
    5. The Royal Gorge Bridge is the highest suspension bridge in the United States. In which U.S. state is it located?
    <BR>
    <INPUT TYPE="RADIO" NAME="Question5" VALUE="A" checked> A. California
    <BR>
    <INPUT TYPE="RADIO" NAME="Question5" VALUE="B"> B. Texas
    <BR>
    <INPUT TYPE="RADIO" NAME="Question5" VALUE="C"> C. Montana
    <BR>
    <INPUT TYPE="RADIO" NAME="Question5" VALUE="D"> D. New York
    <BR>
    <INPUT TYPE="RADIO" NAME="Question5" VALUE="E"> E. Colorado
    <P>
    6. What is the official slogan of the Royal Canadian Mounted Police?
    <BR>
    <INPUT TYPE="RADIO" NAME="Question6" VALUE="A" checked> A. "We always get our man"
    <BR>
    <INPUT TYPE="RADIO" NAME="Question6" VALUE="B"> B. "Maintain the right"
    <BR>
    <INPUT TYPE="RADIO" NAME="Question6" VALUE="C"> C. "We are family"
    <BR>
    <INPUT TYPE="RADIO" NAME="Question6" VALUE="D"> D. "Be vigilant"
    <BR>
    <INPUT TYPE="RADIO" NAME="Question6" VALUE="E"> E. "One Mountie, one riot"
    <P>
    7. What comic strip character was the subject of a top ten novelty hit for the Royal Guardsmen in 1966?
    <BR>
    <INPUT TYPE="RADIO" NAME="Question7" VALUE="A" checked> A. Popeye
    <BR>
    <INPUT TYPE="RADIO" NAME="Question7" VALUE="B"> B. Beetle Bailey
    <BR>
    <INPUT TYPE="RADIO" NAME="Question7" VALUE="C"> C. Alley Oop
    <BR>
    <INPUT TYPE="RADIO" NAME="Question7" VALUE="D"> D. Snoopy
    <BR>
    <INPUT TYPE="RADIO" NAME="Question7" VALUE="E"> E. Little Orphan Annie
    <P>
    8. How many lines of verse occur in the stanza form known as "rhyme royal"?
    <BR>
    <INPUT TYPE="RADIO" NAME="Question8" VALUE="A" checked> A. 4
    <BR>
    <INPUT TYPE="RADIO" NAME="Question8" VALUE="B"> B. 5
    <BR>
    <INPUT TYPE="RADIO" NAME="Question8" VALUE="C"> C. 7
    <BR>
    <INPUT TYPE="RADIO" NAME="Question8" VALUE="D"> D. 14
    <BR>
    <INPUT TYPE="RADIO" NAME="Question8" VALUE="E"> E. 16
    <P>
    <CENTER>
    <INPUT TYPE="BUTTON" VALUE="Submit Quiz" onClick="displayResults();">
    <INPUT TYPE="BUTTON" VALUE="Reset">
    </FORM>
    Reply With Quote
      #2  
    Old 05-05-2005, 04:53 PM
    Ultimater's Avatar
    Ultimater Ultimater is offline
    Eccentric Tatertot
     
    Join Date: Jan 2005
    Location: Los Angeles, CA
    Posts: 4,827
    You mis-used the qouble-quotes several times through-out the code... big error...

    For example:
    question[8] = "How many lines of verse occur in the stanza form known as "rhyme royal"?"
    needs to be:
    question[8] = "How many lines of verse occur in the stanza form known as \"rhyme royal\"?"
    __________________
    Ultimater

    XMLHttpRequest:
    Specification | xmlhttp object | open and onreadystatechange order | String.prototype.toXMLDocument | Sarissa | Prototype | Dojo
    Broadening one's horizons:
    24ways.org


    Note I have a bad habit of editing my posts hours at a time and hours later.
    Reply With Quote
      #3  
    Old 05-05-2005, 05:02 PM
    Ultimater's Avatar
    Ultimater Ultimater is offline
    Eccentric Tatertot
     
    Join Date: Jan 2005
    Location: Los Angeles, CA
    Posts: 4,827
    Here's an errorless copy:
    (attachment)
    re-name it to: deggued_script1212.html
    Attached Files
    File Type: txt deggued_script1212.html.txt (9.7 KB, 41 views)
    __________________
    Ultimater

    XMLHttpRequest:
    Specification | xmlhttp object | open and onreadystatechange order | String.prototype.toXMLDocument | Sarissa | Prototype | Dojo
    Broadening one's horizons:
    24ways.org


    Note I have a bad habit of editing my posts hours at a time and hours later.
    Reply With Quote
      #4  
    Old 05-05-2005, 05:53 PM
    Ultimater's Avatar
    Ultimater Ultimater is offline
    Eccentric Tatertot
     
    Join Date: Jan 2005
    Location: Los Angeles, CA
    Posts: 4,827
    http://www.webdeveloper.com/forum/sh...ad.php?t=65007
    __________________
    Ultimater

    XMLHttpRequest:
    Specification | xmlhttp object | open and onreadystatechange order | String.prototype.toXMLDocument | Sarissa | Prototype | Dojo
    Broadening one's horizons:
    24ways.org


    Note I have a bad habit of editing my posts hours at a time and hours later.
    Reply With Quote
    Reply

    Bookmarks


    Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
     
    Thread Tools Search this Thread
    Search this Thread:

    Advanced Search
    Display Modes Rate This Thread
    Rate This Thread:

    Posting Rules
    You may not post new threads
    You may not post replies
    You may not post attachments
    You may not edit your posts

    BB code is On
    Smilies are On
    [IMG] code is Off
    HTML code is Off
    Forum Jump


    All times are GMT -5. The time now is 02:56 PM.



    Acceptable Use Policy


    The Network for Technology Professionals

    Search:

    About Internet.com

    Legal Notices, Licensing, Permissions, Privacy Policy.
    Advertise | Newsletters | E-mail Offers

    Powered by vBulletin® Version 3.7.3
    Copyright ©2000 - 2010, Jelsoft Enterprises Ltd.