Scripts in the body section will be executed WHILE the page loads. Scripts in the head section will be executed when CALLED. Zippidy doo da!

The actual script is in an external script file called "xxx.js".

---------------- You can create a variable with the var statement: var strname = some value You can also create a variable without the var statement: strname = some value ------------------

By pressing the button, a function will be called. The function will alert a message.

---------------

The script in the body section calls a function with two arguments, 2 and 3.

The function returns the sum of these two arguments.

---------- switch (expression) { case label1: code to be executed if expression = label1 break case label2: code to be executed if expression = label2 break default: code to be executed if expression is different from both label1 and label2 } ------------- greeting=(visitor=="PRES")?"Dear President ":"Dear " ------------- ---------- ------------------ ------------- 0 is boolean false 1 is boolean true An empty string is boolean false null is boolean false NaN is boolean false The string 'false' is boolean true ------------ r_number=Math.random() To store the rounded number of 8.6 in a variable called "r_number": r_number=Math.round(8.6) The Math object's properties and methods are described below: NN: Netscape, IE: Internet Explorer Properties Syntax: object.property_name Property Description NN IE E Returns the base of a natural logarithm 2 3 LN2 Returns the natural logarithm of 2 2 3 LN10 Returns the natural logarithm of 10 2 3 LOG2E Returns the base-2 logarithm of E 2 3 LOG10E Returns the base-10 logarithm of E 2 3 PI Returns PI 2 3 SQRT1_2 Returns 1 divided by the square root of 2 2 3 SQRT2 Returns the square root of 2 2 3 Methods Syntax: object.method_name() Method Description NN IE abs(x) Returns the absolute value of x 2 3 acos(x) Returns the arccosine of x 2 3 asin(x) Returns the arcsine of x 2 3 atan(x) Returns the arctangent of x 2 3 atan2(y,x) Returns the angle from the x axis to a point 2 3 ceil(x) Returns the nearest integer greater than or equal to x 2 3 cos(x) Returns the cosine of x 2 3 exp(x) Returns the value of E raised to the power of x 2 3 floor(x) Returns the nearest integer less than or equal to x 2 3 log(x) Returns the natural log of x 2 3 max(x,y) Returns the number with the highest value of x and y 2 3 min(x,y) Returns the number with the lowest value of x and y 2 3 pow(x,y) Returns the value of the number x raised to the power of y 2 3 random() Returns a random number between 0 and 1 2 3 round(x) Rounds x to the nearest integer 2 3 sin(x) Returns the sine of x 2 3 sqrt(x) Returns the square root of x 2 3 tan(x) Returns the tangent of x 2 3 -------------------- ---------------------

This example tests if a string contains a specified word. If the word is found it returns the position of the first character of the word in the original string. Note: The first position in the string is 0!

--------------------------- anchor("anchorname") Returns a string as an anchor 2 3 big() Returns a string in big text 2 3 blink() Returns a string blinking 2 bold() Returns a string in bold 2 3 charAt(index) Returns the character at a specified position 2 3 charCodeAt(i) Returns the Unicode of the character at a specified position 4 4 concat() Returns two concatenated strings 4 4 fixed() Returns a string as teletype 2 3 fontcolor() Returns a string in a specified color 2 3 fontsize() Returns a string in a specified size 2 3 fromCharCode() Returns the character value of a Unicode 4 4 indexOf() Returns the position of the first occurrence of a specified string inside another string. Returns -1 if it never occurs 2 3 italics() Returns a string in italic 2 3 lastIndexOf() Returns the position of the first occurrence of a specified string inside another string. Returns -1 if it never occurs. Note: This method starts from the right and moves left! 2 3 link() Returns a string as a hyperlink 2 3 match() Similar to indexOf and lastIndexOf, but this method returns the specified string, or "null", instead of a numeric value 4 4 replace() Replaces some specified characters with some new specified characters 4 4 search() Returns an integer if the string contains some specified characters, if not it returns -1 4 4 slice() Returns a string containing a specified character index 4 4 small() Returns a string as small text 2 3 split() Splits a string into an array of strings 4 4 strike() Returns a string strikethrough 2 3 sub() Returns a string as subscript 2 3 substr() Returns the specified characters. 14,7 returns 7 characters, from the 14th character (starts at 0) 4 4 substring() Returns the specified characters. 7,14 returns all characters from the 7th up to but not including the 14th (starts at 0) 2 3 sup() Returns a string as superscript 2 3 toLowerCase() Converts a string to lower case 2 3 toUpperCase() Converts a string to upper case 2 3 --------------

Click in the document. An alert box will alert the x and y coordinates of the cursor.

---------------------

Click somewhere in the document. An alert box will alert the x and y coordinates of the cursor.

---------------------
Enter some text (you will get a message if you add more than 5 characters):
------------------
-------------------