SitePoint Sponsor

User Tag List

Results 1 to 9 of 9
  1. #1
    SitePoint Member
    Join Date
    Jun 2008
    Posts
    8
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    No output on IE or Mozilla

    Hi. I am trying to do my first website using JavaScript but so far I have no output on IE or mozilla.

    The idea is that when the website is open the user gets a welcome message and a paragraph about the theme of the page. then you answer some questions and finally you put to graphics related to your theme.

    Could you help me.... thanks

    this is my code

    Code:
    <html> 
    <head>
            <title>JavaScript</title>
            <script language="JavaScript">
    	       
    	var Stringquestiona = 'JavaScript';
    	var Stringquestionb = 'The data types in JavaScript are: Numeric, String, Logical, JavaScript Element, Null, and Date ';
    	var Stringquestionc = 'PERL, ASP, PHP';
    	var Stringquestiond = 'Translate a program into machine language '; 
    	var Stringquestione = 'HTTP (Hypertext Transfer Protocol) is a protocol which governs "how" communication
                               happen and the structure for those communications ';
    	var Stringquestionf = 'CGI (Common Gateway Interface) is a program which manages information going
                               in and out of a web server. CGI is not a programming language itself, it is a protocol
                               for the rules controlling how a web server comunicates with the outside world. 
                               CGI programs may be written in any programming language (conpiled or interpreted)'; 
    	var Stringquestiong = 'If, While, For';
    	var Stringquestionh = 'if(a != b) { document.write(a is not equal to c)}' ;
    
    	var Stringquestioni = 'if(a = c) {document.write("a" is equal to "c")}';
    
    	var Stringquestionj = 'if(a = >c) {document.write("a" is greater than or equal to "c")}';
    	var myString = "";
    	var answerString = "mythological"; 
        newImage1 = new Image ()
        newImage2 = new Image ()
    
    
    </script>
    </head>
    <body>
    <script language="JavaScript">
                             document.write('<h1>Welcome to my website</h1><h2> The theme is "Unicorns"</h2>
                            Since I remember I have Unicorns around me. Are they special? YES. 
                            They are beautiful and pure creatures. So, this is my hobby... to collect them.<br>
                             A unicorn (from Latin unus "one" and cornu "horn") is a mythological creature often used in
                             fantasy stories, picture book, and novels.Though the modern popular image of the unicorn
                             is sometimes that of a horse differing only in the horn on its forehead, the traditional
                             unicorn has a billy-goat beard, a lion's tail, and cloven hooves - these distinguish it from a horse.');
                             <br><br>    
    
                      
                      document.write('Answer the following questions:');<br>
    
    	document.write('a) If a script is processed client side, what program does the interpreting?<br>'
                        + Stringquestiona '<br><br>');
    
    	document.write('b) Name the data types in JavaScript.'<br> + Stringquestionb <br><br>) ;
    
    	document.write('c) If a program is processed server side, what program does the interpreting?'
                            <br> + Stringquestionc <br><br>);
    
    	document.write('d) What does compiling a program actually do?<br>'
                           + Stringquestiond '<br><br>');
    
    
    	document.write('e) What function does the HTTP protocol perform?<br>'
                            + Stringquestione '<br><br>');
    
    
    	document.write('f) What is the acronym CGI an abbreviation for, and what is a CGI?<br>'
                             + Stringquestionf '<br><br>');
    
    	document.write('g) Name the control structures in JavaScript?<br>'
                              + Stringquestiong '<br><br>');
    
    	document.write('h) Show the code for the following -- if variable "a" is not equal to variable "c" print a message reading "a is not equal to c".<br>'
                               + Stringquestionh '<br><br>');
    
    	document.write('i) Show the code for the following - if variable "a" is equal to variable "c" print a message reading "a is equal to c".<br>'
                                 + Stringquestionie '<br><br>');
    
    	document.write('j) Show the code for the following - if variable "a" is greater than or equal to "c" print a message reading "a is greater than or equal to c".<br>'
                                 + Stringquestionj '<br><br>');
    
    
    myString = prompt(" is a Unicorn a mythological or a fantasy creature?", "");
    <input type = "text" name="result"><br><br>
    
    
    while (result != answerString)
    {
    document.write("The answer is incorrect. Try again...");
    }
    
    alert("You did it!!!! Congratulations");
    
    for(x=1; x <=7; x++) {
    document.write("Out of a possible 7 lines, this is the" + x + "line <br>");
    
    newImage1.src = "Unicornio.gif"   
    newImage2.src = "Unicornio1.gif" 
    
    document.images[0].src = newImage1.src
    document.images[1].src = newImage2.src
    
    
    </script>
    </body>
    
    </html>

  2. #2
    Unobtrusively zen silver trophybronze trophy
    paul_wilkins's Avatar
    Join Date
    Jan 2007
    Location
    Christchurch, New Zealand
    Posts
    14,705
    Mentioned
    101 Post(s)
    Tagged
    4 Thread(s)
    If you're using Internet Explorer, go to Tools > Internet Options and enable the checkbox for Display a notification about every script error

    If you're using Firefox then in the Tools menu open up the Error Console

    There are a number of problems, mostly relating to string errors.
    Something that should help is http://jennifermadden.com/javascript...Character.html

    Also, when you're writing out html code from javascript, that has to be in quotes too, such as the <br> codes that you use. For example:

    Code javascript:
    	document.write('b) Name the data types in JavaScript.<br>' + Stringquestionb + '<br><br>') ;
    Programming Group Advisor
    Reference: JavaScript, Quirksmode Validate: HTML Validation, JSLint
    Car is to Carpet as Java is to JavaScript

  3. #3
    SitePoint Member
    Join Date
    Jun 2008
    Posts
    8
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Thanks pmw57 for your suggestions. I did some changes and now works but there are some little details.

    1. I am trying to put a graphic (red color text) but so far no results. I don't know if I am missing something.

    2. When I load the website, a windows asks a question, if the user answer right, the next instruction (blue color text) prints ok leaving a space in between the lines; but if the user answer the question wrong then the next instruction prints at the same time that the 7 lines. How can I create a standard space (1 line) so this not happen again.

    Thanks

    Code:
    <html> 
    <head>
            <title>JavaScript</title>
            <script type="text/javascript">
    	       
    	var Stringquestiona = 'JavaScript';
    	var Stringquestionb = 'The data types in JavaScript are: Numeric, String, Logical, JavaScript Element, Null, and Date ';
    	var Stringquestionc = 'PERL, ASP, PHP';
    	var Stringquestiond = 'Translate a program into machine language '; 
    	var Stringquestione = 'HTTP (Hypertext Transfer Protocol) is a protocol which governs "how" communication happen and the structure for those communications ';
    	var Stringquestionf = 'CGI (Common Gateway Interface) is a program which manages information going in and out of a web server. CGI is not a programming language itself, it is a protocol for the rules controlling how a web server comunicates with the outside world. CGI programs may be written in any programming language (compiled or interpreted)'; 
    	var Stringquestiong = 'If, While, For';
    	var Stringquestionh = 'if(a != b) { document.write(a is not equal to c)}' ;
    	var Stringquestioni = 'if(a = c) {document.write("a" is equal to "c")}';
    	var Stringquestionj = 'if(a = >c) {document.write("a" is greater than or equal to "c")}';
    	var myString = "";
    	var answerString = "mythological"; 
                      newImage1 = new Image ()
                      newImage2 = new Image ()
    
    
    </script>
    </head>
    <body>
    <script type="text/javascript">
    document.write('<h1>Welcome to my website</h1><h2> The theme is "Unicorns"</h2> Since I remember I have Unicorns around me. Are they special? YES. They are beautiful and pure creatures. So, this is my hobby... to collect them.<br> A unicorn (from Latin unus "one" and cornu "horn") is a mythological creature often used in fantasy stories, picture book, and novels.Though the modern popular image of the unicorn is sometimes that of a horse differing only in the horn on its forehead, the traditional unicorn has a billy-goat beard, a lion\'s tail, and cloven hooves - these distinguish it from a horse.<br><br>');
    document.write('<h3>Answer the following questions:</h3><br>');
    document.write('a) If a script is processed client side, what program does the interpreting?<br>' + Stringquestiona +'<br><br>');
    
    	document.write('b) Name the data types in JavaScript.<br>' + Stringquestionb +'<br><br>') ;
    
    	document.write('c) If a program is processed server side, what program does the interpreting?<br>' + Stringquestionc+ '<br><br>');
    
    	document.write('d) What does compiling a program actually do?<br>' + Stringquestiond+ '<br><br>');
    
    	document.write('e) What function does the HTTP protocol perform?<br>'
                            + Stringquestione+ '<br><br>');
    
    	document.write('f) What is the acronym CGI an abbreviation for, and what is a CGI?<br>'
                             + Stringquestionf +'<br><br>');
    
    	document.write('g) Name the control structures in JavaScript?<br>'
                              + Stringquestiong +'<br><br>');
    
    	document.write('h) Show the code for the following -- if variable "a" is not equal to variable "c" print a message reading "a is not equal to c".<br>'
                               + Stringquestionh+'<br><br>');
    
    	document.write('i) Show the code for the following - if variable "a" is equal to variable "c" print a message reading "a is equal to c".<br>'
                                 + Stringquestione +'<br><br>');
    
    	document.write('j) Show the code for the following - if variable "a" is greater than or equal to "c" print a message reading "a is greater than or equal to c".<br>'
                                 + Stringquestionj +'<br><br>');
    
    
    myString = prompt(" is a Unicorn a mythological or a fantasy creature?", "");
    
    if(myString != answerString)
    {
    document.write("The answer is incorrect. Try again...");
    }
    else
    {
    alert("You did it!!!! Congratulations");
    }
    
    for(x=1; x <=7; x++) {
    document.write("Out of a possible 7 lines, this is the " + x + " line <br>");}
    
    newImage1.src = "Unicornio.gif"   
    newImage2.src = "Unicornio1.gif" 
    
    document.images[0].src = newImage1.src
    document.images[1].src = newImage2.src
    
    
    
    </script>
    </body>
    
    </html>

  4. #4
    Unobtrusively zen silver trophybronze trophy
    paul_wilkins's Avatar
    Join Date
    Jan 2007
    Location
    Christchurch, New Zealand
    Posts
    14,705
    Mentioned
    101 Post(s)
    Tagged
    4 Thread(s)
    You could add the spacing as you have with the other lines

    Code javascript:
    document.write("The answer is incorrect. Try again..." + '<br><br>');
    Programming Group Advisor
    Reference: JavaScript, Quirksmode Validate: HTML Validation, JSLint
    Car is to Carpet as Java is to JavaScript

  5. #5
    SitePoint Member
    Join Date
    Jun 2008
    Posts
    8
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Hi. Thanks I got it. my last point is that I need to use a WHILE structure in this code instead of a FOR structure. I tried but always a syntax error.

    Thanks


    Code:
    if(myString != answerString)
    {
    document.write("The answer is incorrect. Try again...");
    }
    else
    {
    alert("You did it!!!! Congratulations");
    }

  6. #6
    Unobtrusively zen silver trophybronze trophy
    paul_wilkins's Avatar
    Join Date
    Jan 2007
    Location
    Christchurch, New Zealand
    Posts
    14,705
    Mentioned
    101 Post(s)
    Tagged
    4 Thread(s)
    Here is a while loop

    Code javascript:
    x = 1;
    while (x <= 7) {
        document.write("Out of a possible 7 lines, this is the " + x + " line <br>");
        x += 1;
    }
    Programming Group Advisor
    Reference: JavaScript, Quirksmode Validate: HTML Validation, JSLint
    Car is to Carpet as Java is to JavaScript

  7. #7
    SitePoint Member
    Join Date
    Jun 2008
    Posts
    8
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Thanks pmw57 but the structure that I need to change is this:

    Code:
    myString = prompt(" is a Unicorn a mythological or a fantasy creature?", "");
    
    if(myString != answerString)
    {
    document.write("The answer is incorrect. Try again...");
    }
    else
    {
    alert("You did it!!!! Congratulations");
    }

  8. #8
    Unobtrusively zen silver trophybronze trophy
    paul_wilkins's Avatar
    Join Date
    Jan 2007
    Location
    Christchurch, New Zealand
    Posts
    14,705
    Mentioned
    101 Post(s)
    Tagged
    4 Thread(s)
    Well the while structure doesn't change.

    Code javascript:
    var myString = '';
    while (myString !== 'mythological') {
        myString = prompt(" is a Unicorn a mythological or a fantasy creature?", "");
    }
    alert("You did it!!!! Congratulations");
    Programming Group Advisor
    Reference: JavaScript, Quirksmode Validate: HTML Validation, JSLint
    Car is to Carpet as Java is to JavaScript

  9. #9
    SitePoint Member
    Join Date
    Jun 2008
    Posts
    8
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Wonderful pmw57. I got it.

    Thanks for your prompt answer. The file is done and working fine.


Bookmarks

Posting Permissions

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