09/08/2005 CISC103 Lecture Notes

A sample HTML file containing JavaScript

Look at start.html

Show what happens when you open in Firefox and Internet Explorer

IE may warn about "active content".

Several ways to use JavaScript (from EssDesign JS1 p. 4ff)*

  1. Embedding code in <script> tags
  2. Using inline code within HTML code
  3. Defining code in the <head> section of an HTML document as a function, then calling that function in the body.
  4. Storing JavaScript code in a separate file. Allows sharing of code among multiple documents.

*Note: "EssDesign JS1" will be my abbreviation for "Essentials for Design: JavaScript Level 1". See the course syllabus for a complete citation of this textbook. Similarly, I'll use abbreviations such as "EssDesign XHTML1" and EssDesign JS2"

Methods

Playing with JavaScript Expressions in the command line


You can type in javascript: in the URL box 
of the Firefox browser, and follow it with 
a JavaScript expression.
That will let you see the result.

Some expressions to try:

3 + 4
3 * 6
8 / 4
4 / 8
2 * 4 + 5
2 + 4 * 5
a = 4; a + 1
a = 4; b = 5; c = 6; b - a + c
9 % 3
10 % 3
11 % 3
12 % 3
13 % 3
Date
new Date
"foo"
"foo" + 1
"foo" + 1 + 3
xmas = new Date(2005, 12, 25); xmas
"foo" + 1 * 3 
"foo" + 2 * 3
alert("Hi")