JavaScript Programming Workshop Manual 3

Marshall School of Business University of Southern California JavaScript-WS3 June 28, 2000 Page 13 Array, IF, Counter Example 2: Building A Wrap Around Slide Show In the previous slide … Marshall School of Business University of Southern California JavaScript-WS3 June 28, 2000 Page 5 General Flow When the user clicks on one of the hyperlinks (February 3rd for example), the “BIO” function is called. The number contained within the hyperlink for February 3rd (3) gets passed to the “BIO” function and is stored in “THIS_DAY” within the … … 18.3 Initializing the Elements of an Array ….. 82 18.4 Accessing the Elements of a JavaScript Array …
ARRAYS An array is an object that contains an indexed series of elements. The elements can be numbers, strings (text), other objects, or combinations of all three. An element can even be another array. Further, these objects can be specified when you define the array or you can create an empty array and fill it later. Creating an Array – Method 1 ? ? The items in a filled array must be separated by commas ? ? The array object is created by using the “new” command. ArrayName = new Array(element0, element1, element2,…) Example: Pets = new Array(“Cats”,”Dogs”,”Birds”) Creating an Array – Method 2 This type of array is structured vertically with the array elements in square braces [ ]. The Array is named in the first line and its elements are assigned in succeeding lines. Syntax : ArrayName = new Array() ArrayName[1] ArrayName[2] ArrayName[3] Example : Pets= new Array() Pets["Cats"] Pets["Dogs"] Pets["Birds"] Calling An Array An array is called by specifying the name of the array followed by the index value you wish to return contained in square braces. Syntax: NameOfArray[Index Number] Example: Pets[1] Method 1 would return: Dogs Method 2 would return: Cats…. This section of code creates the hyperlinks that the user will see on the page. When the user clicks one of these hyperlinks, the BIO function is called and the number in parenthesis is sent to the function as its argument (THIS_DAY). ” javascript:name of function(argument) ” or “javascript:BIO(1) for example, is the syntax used to call a function from a hyperlink….. The If Function An “If” statement is a built in function that will execute its statements only if a user created condition is true. The syntax of an “if” statement is shown below: if(condition) {What to do if condition is TRUE} else {What to do if condition is FALSE} “if” is the name of the function. The condition section of the function must be in round braces ( ). The Code in these { } executes only if the condition is TRUE. “else” is optional and only
Download JavaScript Programming Workshop Manual 3.Pdf