Lecture Summary 4

Prepared by: Anthony Larrain


Introduction to JavaScript


First Example

<html> <head> <title> Greetings</title> </head> <body> <h3>First JavaScript Example</h3> <script type="text/javascript"> var name = prompt("Enter your name", ""); document.write("Greetings " + name + ", welcome to my page."); </script> <p>Here you will find all sorts of far out and groovy stuff I am into.</p> </body> </html>

greet.html


Basic Terms and Features

  • The following command allows you to write text to the HTML document using Javascript.
  •  document.write("Hello Class");
     
  • The symbol ' + ' has multiple meanings in JavaScript. One usage is for string concatenation.
  •  document.write("Hello " + "Class");
     
  • When an operand to plus is a variable the value of the variable is used not the variable itself.
  •  var name = "Class";
     document.write("Hello " + name);     
     

    The above would display

     Hello Class
     

    Not

     Hello name
     
  • Since the document.write(... command will write text to then HTML file, you can add HTML tags to the text.
  • document.write("<p>Hello Class</p>);

    JavaScript Variables


    Arithmetic Operators

    @Anthony Larrain 2005 - 2006

    Send Questions or Comments to hci201@yahoo.com