Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Page 1 of 2 12 LastLast
Results 1 to 15 of 16
  1. #1
    New Coder
    Join Date
    Oct 2003
    Posts
    17
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Simple Quiz Problem

    I am just starting to learn javascript and have written the code for a simple quiz. The quiz asks a question and prompts for an answer. If the answer is wrong you can either click on a button to try again or place the mouse over a link to get a clue. However, when the answer is correct the try again button and the clue still appear. How do I correct the code so that the button and the mouseover do not show when the answer is correct?

    Here is the link to the quiz:
    http://users3.ev1.net/~anortham/quiz/quiz.htm

    Thanks for your help in advance!

    Alann

  • #2
    Regular Coder COBOLdinosaur's Avatar
    Join Date
    Jul 2002
    Location
    Canada
    Posts
    404
    Thanks
    2
    Thanked 32 Times in 32 Posts
    Change the layer to keep it hidden:

    <div id=thediv" style="display:none">
    <DIV align=center>
    <P>&nbsp;</P>
    <P>&nbsp;</P>
    <P>&nbsp;</P>
    <P></P>
    <P align=center>
    <FORM><INPUT name=button onclick="window.location='quiz.htm'" type=button value="Try Again"></FORM></P></DIV>
    <P>&nbsp;</P>
    <P align=center><A href="" onmouseover="alert('They are not Red')">Clue</A></P></div>

    Then change the script to:

    else
    {
    document.write("<CENTER><H1>'Your answer is incorrect!'<\/H1><\/CENTER>");
    document.write("<CENTER><FONT size=4>'The correct answer will be given on Monday'<\/FONT>
    document.getElementByid('thediv').display='block';
    <\/CENTER>");

    }
    100% standards compliant code is 100% correct 100% of the time.
    one of my toys from my repository and perhaps some help getting help

    Cd&

  • #3
    New Coder
    Join Date
    Oct 2003
    Posts
    17
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Thanks "COBOLdinosaur" for the code!

    I have made the changes but looks like I either made a mistake in implementing the code or it still needs a few more tweeks.

    The link to the modified code is: http://users3.ev1.net/~anortham/quiz/quiz_modified.htm

    The link to the original code is still at: http://users3.ev1.net/~anortham/quiz/quiz.htm

    I appreciate your help!
    Alann,

  • #4
    Kor
    Kor is offline
    Red Devil Mod Kor's Avatar
    Join Date
    Apr 2003
    Location
    Bucharest, ROMANIA
    Posts
    8,478
    Thanks
    58
    Thanked 379 Times in 375 Posts
    there is an unterminated strings literal. add the bolded below:

    document.write("<CENTER><FONT size=4>'The correct answer will be given on Monday'<\/FONT>");
    KOR
    Offshore programming
    -*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*

  • #5
    New Coder
    Join Date
    Oct 2003
    Posts
    17
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Thanks Kor for pointing out the error! Corrections to code per Kor's recommendations have been made. Problem still exists!

    Alann,

    (See links in my last response...)

  • #6
    Kor
    Kor is offline
    Red Devil Mod Kor's Avatar
    Join Date
    Apr 2003
    Location
    Bucharest, ROMANIA
    Posts
    8,478
    Thanks
    58
    Thanked 379 Times in 375 Posts
    I see now that there might be another syntax problem

    if you use document.write("whichever")

    you don'y need to use

    document.write("whic 'e'ver")

    so remove all the ' inside the string

    document.write("bla") writes exactly (except some reserved as " or ' inside - which must be specified as string element with backslash - \" or \') what there must be as HTML line codes.

    So:

    Code:
    document.write("<CENTER><H1>Your answer is incorrect!</H1></CENTER>");
    document.write("<CENTER><FONT size=4>The correct answer will be given on Monday</FONT>
    try this above
    KOR
    Offshore programming
    -*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*

  • #7
    Kor
    Kor is offline
    Red Devil Mod Kor's Avatar
    Join Date
    Apr 2003
    Location
    Bucharest, ROMANIA
    Posts
    8,478
    Thanks
    58
    Thanked 379 Times in 375 Posts
    I see you have not made the previous changes, so try this again:

    Code:
    document.write("<CENTER><H1>Your answer is incorrect!</H1></CENTER>");
    document.write("<CENTER><FONT size=4>The correct answer will be given on Monday</FONT>");
    KOR
    Offshore programming
    -*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*

  • #8
    New Coder
    Join Date
    Oct 2003
    Posts
    17
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Corrections made per "Kor's" recommendations. Problem still exists.

    I moved the <\/CENTER>"); code and now the quiz partially works. However the TRY AGAIN button and the TIP link are still being hid all the time.

    The link to the modified code is: http://users3.ev1.net/~anortham/quiz/quiz_modified.htm

    The link to the original code is still at: http://users3.ev1.net/~anortham/quiz/quiz.htm

  • #9
    Regular Coder COBOLdinosaur's Avatar
    Join Date
    Jul 2002
    Location
    Canada
    Posts
    404
    Thanks
    2
    Thanked 32 Times in 32 Posts
    Sorry there is an error in the code I posted:

    This:

    document.getElementByid('thediv').display='block';

    Should be:

    document.getElementById('thediv').style.display='block';

    Sometimes I try to type faster than it is possible for a dinosaur to move.
    100% standards compliant code is 100% correct 100% of the time.
    one of my toys from my repository and perhaps some help getting help

    Cd&

  • #10
    New Coder
    Join Date
    Oct 2003
    Posts
    17
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Made correction to code per "COBOLdinosaur" recommendation. Problem still exists!

  • #11
    Senior Coder
    Join Date
    Jun 2002
    Location
    Nashua, NH
    Posts
    1,724
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Just out of curiosity: there are so many javascript quizes, why trying to reinvent the wheel?
    Vladdy | KL
    "Working web site is not the one that looks the same on common graphical browsers running on desktop computers, but the one that adequately delivers information regardless of device accessing it"

  • #12
    New Coder
    Join Date
    Oct 2003
    Posts
    17
    Thanks
    0
    Thanked 0 Times in 0 Posts
    I am just learning javascript, and I am developing the quiz as an exercise in programming. I got the quiz to work OK but then wanted to hide the button when the quiz answer is wrong and didn't know how to do it so I am seeking help. The end result is not as important as the learning and understanding of javascript that I am getting.

  • #13
    Regular Coder COBOLdinosaur's Avatar
    Join Date
    Jul 2002
    Location
    Canada
    Posts
    404
    Thanks
    2
    Thanked 32 Times in 32 Posts
    you missed part of the code fix. you inseted style okay, but you missed the spelling mistake in teh method:

    I originally spelled it:
    document.getElementByid

    In the corrected version it is: document.getElementById

    Both JavaScript and the DOM are case sensitive. You were getting a scripting error on the page. If you do not have messaging on, then go to the advanced setting on your IE browser and set it to display every error message, it will save you a lot of time.
    100% standards compliant code is 100% correct 100% of the time.
    one of my toys from my repository and perhaps some help getting help

    Cd&

  • #14
    New Coder
    Join Date
    Oct 2003
    Posts
    17
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Opps!!! Sorry about that. I need to learn to look at the case more closely.

    I made the correction to "document.getElementById" but the button is still not showing when the answer is incorrect.

    I wanted to let you know that I do appreciate all your help

  • #15
    Regular Coder COBOLdinosaur's Avatar
    Join Date
    Jul 2002
    Location
    Canada
    Posts
    404
    Thanks
    2
    Thanked 32 Times in 32 Posts
    Okay I see what is happening. The page structure is wrong. You have an HTML problem. You cannot reference the div before it is created. That is why you get a scripting error. The script need to be in a function.

    It will work fine this way

    <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
    <HTML><HEAD>
    <META content="text/html; charset=windows-1252" http-equiv=Content-Type>
    <SCRIPT language=JavaScript>
    <!--hide
    var correct=false;
    var yourname= prompt('Please enter your answer!', ' ');
    var viewanswer=""
    function setbutton()
    {
    if (!correct) document.getElementById('thediv').style.display='block';
    }
    //-->
    </SCRIPT>

    <META content="MSHTML 5.00.2920.0" name=GENERATOR></HEAD>
    <BODY onLoad="setbutton()" background="" bgColor=#e6e6fa>
    <P align=center>
    <SCRIPT language=JavaScript>
    <!--hide

    if ((yourname=='Blue') || (yourname=='blue') || (yourname=='BLUE'))
    {
    document.write("<CENTER><H1>Your answer is correct!<\/H1><\/CENTER>");
    correct=true;
    }
    else
    {
    document.write("<CENTER><H1>Your answer is incorrect!<\/H1><\/CENTER>");
    document.write("<CENTER><FONT size=4>The correct answer will be given on Monday<\/FONT>)<\/CENTER>");

    }


    //-->
    </SCRIPT>
    </P>
    <div id="thediv" style="display:none">
    <DIV align=center>
    <P>&nbsp;</P>
    <P>&nbsp;</P>
    <P>&nbsp;</P>
    <P></P>
    <P align=center>
    <FORM><INPUT name=button onclick="window.location='quiz.htm'" type=button value="Try Again"></FORM></P></DIV>
    <P>&nbsp;</P>
    <P align=center><A href="" onmouseover="alert('They are not Red')">Clue</A></P></div>
    </BODY></HTML>
    100% standards compliant code is 100% correct 100% of the time.
    one of my toys from my repository and perhaps some help getting help

    Cd&


  •  
    Page 1 of 2 12 LastLast

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •