Extra Slides, week 3

CSE 190 M (Web Programming), Spring 2008

University of Washington

Reading: Chapter 3

Except where otherwise noted, the contents of this presentation are © Copyright 2008 Marty Stepp and Jessica Miller and are licensed under the Creative Commons Attribution 2.5 License.

Valid XHTML 1.1 Valid CSS!

Additional JavaScript

Commands and syntax you won't need on your homework

JavaScript in HTML body (example)

<script type="text/javascript">
	JavaScript code
</script> 

Injecting Dynamic Text: document.write

document.write("message");

The typeof function

typeof(value)

The arguments array

function example() {
	for (var i = 0; i < arguments.length; i++) {
		alert(arguments[i]);
	}
}
example("how", "are", "you");   // alerts 3 times

The "for each" loop

for (var name in arrayOrObject) {
	do something with arrayOrObject[name];
}

Arrays as maps

var map = [];
map[42] = "the answer";
map[3.14] = "pi";
map["champ"] = "suns";

Date object

var today = new Date();               // today
var midterm = new Date(2007, 4, 4);   // May 4, 2007

The eval (evil?) function

eval("JavaScript code");
eval("var x = 7; x++; alert(x / 2);");  // alerts 4

Dr. Evil