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)*
- Embedding code in <script> tags
- Using inline code within HTML code
- Defining code in the <head> section of an HTML document as a function, then
calling that function in the body.
- 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
alert() is a JavaScript method.
- Sometimes methods are also called functions.
- The
() is always present when you invoke a method.
- We sometimes say call a method instead of invoke a method.
- Sometimes you put something in the parentheses that the method uses to do its job; this
thing in the parentheses is called an argument .
- Some folks use the word parameter in place of the word argument. Other folks insist that parameters
and arguments are different things. We'll say more about
this when we talk about defining our own JavaScript functions.
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")