| Alfred Wong's Programming Showcase | ||||||||
|
After selecting link, choose View|Source in Internet Explorer or View|Page Source in Netscape to see code.
BodyParts writes the body part in the status bar when you hover the mouse over it, and shows an alert box when you click on a body part. The map consists of circle, rectangle, and polygon shapes. onMouseOver events write the body part in the status bar. onClick events show an alert box identifying the body part you clicked on. onMouseOut events clear the status bar.
Clock shows a 12-hour clock updating every second.
Concatenation shows the importance of operator precedence and parentheses. I have to use the <pre> tag for writeln to print a new line. I don't indent code because the <pre> tag prints all blanks before the next tag, and so would misalign the first line.
ConvertTemperature converts from celsius to fahrenheit and vice versa. It uses two text boxes for input and output. onClick events call functions to calculate temperatures. Note that I multiply before dividing to ensure maximum precision.
ShowCountry highlights different areas in North America that the mouse is over. The map consists of polygon and circle shapes. onMouseOver events show the map with the area highlighted. onMouseOut events show the unhighlighed map.
Eval shows the strange things that can happen when you mix quotes, string, numbers and the plus sign with the eval function. View source code to see code I had to comment out to prevent run-time error.
FatCatDancing creates animation by switching between three images every .2 seconds. The user starts it with the startInterval method and stops it with the clearInterval method. This loads an image each time. You can avoid this by using image caching and running when the page loads. I've found this unreliable, and users can find animation annoying, so I prefer to leave it under user control.
Navigator shows all the navigator properties, which gives data about your computer.
PrimitiveTypes shows info about JavaScript primitive types. The typeof operator shows datatypes that differ slightly from those described in a book. But after setting a variable to null, the typeof operator shows a datatype of object!
Time shows Universal Time in an alert box. Once you close the alert box, another one will pop up in 60 seconds. For more info on UT and UTC see U.S. Naval Observatory.
|
© 2004 Alfred Wong
|