No output on IE or Mozilla

Discussion in 'JavaScript' started by nogal, Jun 3, 2008.

  1. #1
    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

    
    
    <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>
    
    
    Code (markup):
     
    nogal, Jun 3, 2008 IP
  2. xlcho

    xlcho Guest

    Messages:
    532
    Likes Received:
    8
    Best Answers:
    0
    Trophy Points:
    0
    #2
    Javascript doesn't support multi-line string concatenation, i'm pretty sure thats the main problem. Try writting all you assignments in just one row or concatenate them using +.
     
    xlcho, Jun 3, 2008 IP
  3. xlcho

    xlcho Guest

    Messages:
    532
    Likes Received:
    8
    Best Answers:
    0
    Trophy Points:
    0
    #3
    Here's the edited code, which is now working more or less.. You've had tons of misplaced ' and ;. Also, read a bit more about string concatenation in javascript and the use of html code inside <script> tags. You had about 20 mislplaced <br> tags inside the javascript code, which results in an error..

    <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>'
                                 + Stringquestioni +'<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?", "");
    
    document.write('<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>
    HTML:
    I'm not sure if this is what you want the script to be doing but at least it displays properly now. Good luck :)
     
    xlcho, Jun 3, 2008 IP
  4. nogal

    nogal Peon

    Messages:
    6
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #4
    thanks for your reply xlcho and yes you are right, being my first website in this language I have to learn a lot more about Javascript. I did a couple of more changes and now it is running better, thanks, but still one more detail:

    Question: I am trying to put to images (text in red color) but so far no success. there is no special thing about them it is just to place them on the website. Am I missing something? they are in the same folder as this file.

    Thanks


    
    
    <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>");}
    
    [COLOR="Red"]newImage1.src = "Unicornio.gif"   
    newImage2.src = "Unicornio1.gif" 
    
    document.images[0].src = newImage1.src
    document.images[1].src = newImage2.src[/COLOR]
    
    </script>
    </body>
    </html>
    
    
    
    Code (markup):
     
    nogal, Jun 4, 2008 IP
  5. nogal

    nogal Peon

    Messages:
    6
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #5
    Hi. I got the images. now my final 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

    
    
    if(myString != answerString)
    {
    document.write("The answer is incorrect. Try again...");
    }
    else
    {
    alert("You did it!!!! Congratulations");
    }
    
    
    Code (markup):
     
    nogal, Jun 4, 2008 IP
  6. nogal

    nogal Peon

    Messages:
    6
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #6
    Hi, I got it. The file is working fine.

    Thanks
     
    nogal, Jun 5, 2008 IP