XP New Perspectives on Creating Web Pages with

XP New Perspectives on Creating Web Pages with

XP New Perspectives on Creating Web Pages with HTML Tutorial 8: Programming with JavaScript Creating Web Pages with HTML, 3e Prepared by: C. Hueckstaedt, Tutorial 8 1 Tutorial Objectives

XP Learn about the features of JavaScript Send output to a Web page Work with variables and data Work with expressions and operators Create a JavaScript function Work with arrays and conditional statements Learn about program loops Creating Web Pages with HTML, 3e Prepared by: C. Hueckstaedt, Tutorial 8 2

XP Introduction to JavaScript JavaScript is an interpreted programming or script language from Netscape. JavaScript is used in Web site development to such things as: automatically change a formatted date on a Web page cause a linked-to-page to appear in a popup window cause text or a graphic image to change during a mouse rollover Resource: www.whatis.com Creating Web Pages with HTML, 3e Prepared by: C. Hueckstaedt, Tutorial 8

3 XP Server-Side and Client-Side Programs Previously, you learned how to access CGI scripts that run from a Web server. There are some disadvantages to this approach: must be connected to the Web server to run the CGI script only the programmer can create or alter the script the Web servers system administrator can place limitations on how users access the script the system administrator has to be concerned about users continually accessing the server and potentially overloading the system Creating Web Pages with HTML, 3e Prepared by: C. Hueckstaedt, Tutorial 8

4 Server-Side and Client-Side Programming XP This figure shows the issues like those previously mentioned that led to the development of programs, or scripts, that could be run from the Web browser (the client). Creating Web Pages with HTML, 3e Prepared by: C. Hueckstaedt, Tutorial 8 5 XP

Client-Side Programs Client-side programs: solve many of the problems associated with server-side scripts computing is distributed over the Web, so that no one server is overloaded with programming requests can be tested locally without first uploading it to a Web server are likely to be more responsive to the user can never completely replace CGI scripts Creating Web Pages with HTML, 3e Prepared by: C. Hueckstaedt, Tutorial 8 6 The Development of

Java and JavaScript XP In 1990, Sun Microsystems programmers developed a program, called Oak that would network and control elements using a single operating system. Oak was extremely reliable and flexible, however, the project did not succeed. Oak was modified in 1995 and renamed Java. Sun Microsystems also developed a product called HotJava, which ran programs written in the Java language. HotJava was a Java interpreter, which means it can interpret and run Java programs. Creating Web Pages with HTML, 3e Prepared by: C. Hueckstaedt, Tutorial 8

7 The Development of Java and JavaScript Continued XP Java could run on the UNIX, Windows, DOS, and Macintosh operating systems. Java is platform-independent. Netscape and Internet Explorer incorporated a Java interpreter in their browser versions. A problem with Java was that nonprogrammers found it difficult to learn and use. Users also needed access to the Java Developers Kit (JDK) in order to create a Java program and then compile it. Creating Web Pages with HTML, 3e

Prepared by: C. Hueckstaedt, Tutorial 8 8 Applets and Java Interpreters XP This figure shows a web browser that has a Java interpreter runs the program locally on the users computer, freeing up the Web server for other purposes. Creating Web Pages with HTML, 3e Prepared by: C. Hueckstaedt, Tutorial 8 9 XP

The Development of Java and JavaScript Continued Compiling is the process by which a program is converted from a text file of code into an executable file called an applet To simplify this complex process, developers from Netscape and Sun Microsystems created a subset of Java called JavaScript. Creating Web Pages with HTML, 3e Prepared by: C. Hueckstaedt, Tutorial 8 10 XP

Differences between Java and JavaScript There are several important differences between Java and JavaScript: users dont need to work with a developers kit to compile a JavaScript program JavaScript commands can be inserted directly into an HTML file rather than being placed in a separate program file JavaScript may not be as powerful a computing language as Java, but it is simpler to use JavaScript meets the needs of most users who want to create programmable Web pages Creating Web Pages with HTML, 3e Prepared by: C. Hueckstaedt, Tutorial 8 11

XP Comparison of Java and JavaScript This figure highlights some of the key differences between Java and JavaScript. Creating Web Pages with HTML, 3e Prepared by: C. Hueckstaedt, Tutorial 8 12 JavaScript XP Internet Explorer supports a slightly different version of JavaScript called JScript. JScript is identical to JavaScript, but there are

some JavaScript commands not supported in JScript, and vice versa. Always test JavaScript programs on a variety of Web browsers. Creating Web Pages with HTML, 3e Prepared by: C. Hueckstaedt, Tutorial 8 13 ECMAScript XP The responsibility for the development of a scripting standard has been transferred to an international body called the European Computer Manufacturers

Association (ECMA). The standard developed by the ECMA is called ECMAScript, though browsers still refer to it as JavaScript. The latest version is ECMA-262, which is supported by the major browsers. Creating Web Pages with HTML, 3e Prepared by: C. Hueckstaedt, Tutorial 8 14 XP Versions of JavaScript and JScript This figure lists the versions of JavaScript or JScript and the corresponding browser support.

Creating Web Pages with HTML, 3e Prepared by: C. Hueckstaedt, Tutorial 8 15 XP Other Client-Side Programming Languages Other client-side programming languages are also available to Web page designers, such as the Internet Explorer scripting language, VBScript. VBScript is an interpreted script language from Microsoft, it is similar to Netscapes JavaScript.* *Resource: www.whatis.com

Creating Web Pages with HTML, 3e Prepared by: C. Hueckstaedt, Tutorial 8 16 XP Example of Web Site using JavaScript Creating Web Pages with HTML, 3e Prepared by: C. Hueckstaedt, Tutorial 8 17 XP Writing a JavaScript Program

Before writing a program, its a good idea to outline the main tasks you want the program to perform. The Web browser runs a JavaScript program when the Web page is first loaded, or in response to an event. JavaScript programs can either be placed directly into the HTML file or they can be saved in external files. placing a program in an external file allows you to hide the program code from the user source code placed directly in the HTML file can be viewed by anyone More complicated and larger the JavaScript program are usually placed in an external file. Creating Web Pages with HTML, 3e Prepared by: C. Hueckstaedt, Tutorial 8

18 Writing a JavaScript Program Continued XP Your program can be placed anywhere within the HTML file. Many programmers favor placing their programs between tags in order to separate the programming code from the Web page content and layout. Some programmers prefer placing programs within the body of the Web page at the location where the program output is generated and displayed. Creating Web Pages with HTML, 3e

Prepared by: C. Hueckstaedt, Tutorial 8 19 Using the When a Web browser that doesnt support scripts encounters this code, it ignores the

string variables is any group of characters, such as Hello or Happy Holidays! Boolean variables are variables that accept one of two values, either true or false null variables is a variable that has no value at all Creating Web Pages with HTML, 3e Prepared by: C. Hueckstaedt, Tutorial 8 32 XP Declaring a Variable Before you can use a variable in your program, you need to create it; also known as declaring a variable.

You declare a variable in JavaScript using the var command or by assigning the variable a value. Any of the following commands is a legitimate way of creating a variable named Month: var Month; var Month = December; Month = December; the first command creates the variable without assigning it a value, while the second and third commands both create the variable and assign it a value Creating Web Pages with HTML, 3e Prepared by: C. Hueckstaedt, Tutorial 8 33 Declaring a Variable Continued

XP Its good programming to include the var command whenever you create a variable. Many Web designers place all of their variable declarations at the beginning of the program along with comments describing the purpose of each variable in the program. The following are some JavaScript variables: Today - containing information about the current date and time ThisDay - storing the current day of the month ThisMonth - storing a number indicating the current month

ThisYear - storing a number indicating the current year DaysLeft - storing number of days until a selected date Creating Web Pages with HTML, 3e Prepared by: C. Hueckstaedt, Tutorial 8 34 Declaring JavaScript Variables XP This figure shows an example of declaring JavaScript variables. Creating Web Pages with HTML, 3e Prepared by: C. Hueckstaedt, Tutorial 8 35

Working with Dates XP JavaScript does not provide a date data type. JavaScript allows you to create a date object, which is an object containing date information. There are two ways to create a date object: variable = new Date(month, day, year, hours:minutes: seconds) or variable = new Date(month, day, year, minutes, seconds) variable is the name of the variable that contains the date information month, day, year, hours, minutes, and seconds indicate the date and time Creating Web Pages with HTML, 3e

Prepared by: C. Hueckstaedt, Tutorial 8 36 XP Retrieving the Day Value The Today variable has all the date and time information you need. JavaScript stores dates and times as the number of milliseconds since 6 p.m on 12/31/69. Use built in JavaScript date methods to do calculations. For each part of the date, or used in a calculation, you need a date method to retrieve its value. For example, if you want the ThisDay variable to store the day of the month. To get that information, apply the getDate() method. The general syntax is:

DayValue = DateObject.getDate() Creating Web Pages with HTML, 3e Prepared by: C. Hueckstaedt, Tutorial 8 37 Retrieving the Day Value XP DayValue is the name of a variable that contains the day of the month DateObject is a date object or a date variable that contains the complete date and time information Creating Web Pages with HTML, 3e Prepared by: C. Hueckstaedt, Tutorial 8

38 XP Retrieving the Month Value The getMonth() method extracts the value of the current month. JavaScript starts counting months with 0 for January, you may want to add 1 to the month number returned by the getMonth() method. The following JavaScript code extracts the current month number, increases it by 1, and stores it in a variable named ThisMonth: ThisMonth = Today.getMonth()+1; for a date of October 15, the ThisMonth variable would have a value of 10.

Creating Web Pages with HTML, 3e Prepared by: C. Hueckstaedt, Tutorial 8 39 XP Retrieving the Year Value The getFullYear() method extracts the year value from the date variable. The following code shows how you would store the value of the current year in a variable you name ThisYear: ThisYear = Today.getFullYear(); if the date stored in the Today variable is October 15, 2003, the value of the getFullYear variable is 2003

Creating Web Pages with HTML, 3e Prepared by: C. Hueckstaedt, Tutorial 8 40 Values of the getYear() method from 1998 to 2001 XP The getYear() method returns only the last two digits of the year for years prior to 2000. This figure shows values of the getYear() method from 1998 to 2001. Creating Web Pages with HTML, 3e Prepared by: C. Hueckstaedt, Tutorial 8 41

Date Methods XP This figure shows most of the date methods you can use with JavaScript. Creating Web Pages with HTML, 3e Prepared by: C. Hueckstaedt, Tutorial 8 42 Retrieving Date Information

with JavaScript XP This figure shows an example of how to retrieve date information with JavaScript. Creating Web Pages with HTML, 3e Prepared by: C. Hueckstaedt, Tutorial 8 43 Displaying the Date Values XP This figure shows an example of a website displaying date values.

Creating Web Pages with HTML, 3e Prepared by: C. Hueckstaedt, Tutorial 8 44 XP Working with Expressions and Operators Expressions are JavaScript commands that assign values to variables. for example, use the expression, DaysLeft=999, to assign to the value 999 to the DaysLeft variable Expressions are created using variables, values, and operators (elements that perform actions within the expression). One of the most commonly used operators is the + operator,

which performs the action of adding or combining two elements. for example, use the plus operator in a program with the following command: var ThisMonth = Today.getMonth()+1; Creating Web Pages with HTML, 3e Prepared by: C. Hueckstaedt, Tutorial 8 45 Arithmetic Operators XP The + operator belongs to a group of operators called arithmetic

operators, which perform simple mathematical calculations. This figure lists some of the arithmetic operators and gives examples of how they work. Creating Web Pages with HTML, 3e Prepared by: C. Hueckstaedt, Tutorial 8 46 Operators

XP Binary operators work on two elements in an expression. Unary operators work on only one variable. unary operators include: the increment (++), decrement (--), and negation (-) operators. The increment operator can be used to increase the value of variable by 1. Creating Web Pages with HTML, 3e Prepared by: C. Hueckstaedt, Tutorial 8 47 XP

An Example of the Increment Operator In the following code, an increment operator is used to increase the value of the x variable by one. x = 100; y = x++; thus, after both commands are run, the value of the x variable is 100 and the value of the y variable is 101 Creating Web Pages with HTML, 3e Prepared by: C. Hueckstaedt, Tutorial 8 48 An Example of the

Decrement Operator XP The decrement operator has the opposite effect, reducing the value of a variable by 1. The following JavaScript code assigns the value 100 to the x variable and 99 to the y variable: x = 100; y = x--; Creating Web Pages with HTML, 3e Prepared by: C. Hueckstaedt, Tutorial 8 49 An Example of the

Negation Operator XP The negation operator changes the sign of a variable: x = -100; y = -x; the value of the x variable is 100, and the value of the y variable is opposite that, or 100 Creating Web Pages with HTML, 3e Prepared by: C. Hueckstaedt, Tutorial 8 50 XP

Assignment Operators Expressions assign values using assignment operators. the most common assignment operator is the equals (=) sign JavaScript provides additional assignment operators that manipulate elements in an expression and assign values within a single operation. one of these is the += operator In JavaScript, the following two expressions create the same results: x = x + y; x += y in both expressions, the value of the x variable is added to the value of the y variable and then the new variable is stored back into the x variable

Creating Web Pages with HTML, 3e Prepared by: C. Hueckstaedt, Tutorial 8 51 XP Assignment Operators Continued An assignment operator also can be used with numbers to increase a variable by a specific amount. for example, to increase the value of the x variable by 2, you can use either of the following two expressions: x = x + 2; x += 2 Creating Web Pages with HTML, 3e

Prepared by: C. Hueckstaedt, Tutorial 8 52 XP The += Operator A common use of the += operator is to create extended text strings. for example, if you have a text string that covers several lines, you may find it difficult to store the text in a variable using a single command. However, you can do so in the following manner: quote = To be or not to be.; quote +=That is the question. ; quote +=Whether tis nobler of the mind to suffer the lings and arrows of

outrageous fortune, ; . . . Creating Web Pages with HTML, 3e Prepared by: C. Hueckstaedt, Tutorial 8 53 Assignment Operators XP This figure shows additional assignment operators that can be used. Assignment operators allow you to create expressions that are both efficient and compact. Creating Web Pages with HTML, 3e Prepared by: C. Hueckstaedt, Tutorial 8

54 XP The Math Object and Math Methods Another way of performing a calculation is to use on the JavaScript built-in Math methods. These methods are applied to an object called the Math object. The syntax for applying a Math method is: value = Math.method(variable); method is the method youll apply to a variable value is the resulting value Creating Web Pages with HTML, 3e Prepared by: C. Hueckstaedt, Tutorial 8

55 An Example of a Math Method XP For example, to calculate the absolute value of a variable named NumVar, you use the abs method as follows: AbsValue = Math.abs(NumVar); the value of the AbsValue variable is set to the absolute value of the NumVar variable Creating Web Pages with HTML, 3e Prepared by: C. Hueckstaedt, Tutorial 8 56

Math Methods XP This figure lists some additional math methods supported by JavaScript. Case is important with JavaScript commands. You must type Math (with an uppercase M) instead of math when using these commands. Creating Web Pages with HTML, 3e Prepared by: C. Hueckstaedt, Tutorial 8 57 Creating JavaScript Functions XP

A function is a series of commands that performs an action or calculates a value. A function consists of the function name, which identifies it; parameters. Parameters are values used by the function; and a set of commands that are run when the function is used. Not all functions require parameters. The general syntax of a JavaScript function is: function function_name(parameters) { JavaScript commands } Creating Web Pages with HTML, 3e Prepared by: C. Hueckstaedt, Tutorial 8 58

XP Creating JavaScript Functions Continued function_name is the name of the function parameters are the values sent to the function JavaScript commands are the actual commands and expressions used by the function Curly braces } are used to mark the beginning and end of the commands in the function. The group of commands set off by the curly braces is called a common block. Creating Web Pages with HTML, 3e Prepared by: C. Hueckstaedt, Tutorial 8 59

XP Creating JavaScript Functions Continued Function names are case-sensitive. The function name must begin with a letter or underscore ( _ ) and cannot contain any spaces. There is no limit to the number of function parameters that a function may contain. The parameters must be placed within parentheses, following the function name, and the parameters must be separated by commas. Creating Web Pages with HTML, 3e Prepared by: C. Hueckstaedt, Tutorial 8

60 XP Performing an Action with a Function The following function displays a message with the current date: function ShowDate(date) { document.write(Today is + date +
); } the function name is ShowDate, and it has one parameter, date there is one line in the functions command block, which displays the current date along with a text string Creating Web Pages with HTML, 3e Prepared by: C. Hueckstaedt, Tutorial 8

61 XP Performing an Action with a Function Continued To run a function, insert a JavaScript command containing the function name and any parameters it requires, this process is known as calling a function. To call the ShowDate function, enter the following commands: var Today = 3/25/2003; ShowDate(Today); the first command creates a variable named Today and assigns it the text string, 3/25/2003 the second command runs the ShowDate function, using the value of the Today variable as a parameter

result is Today is 3/25/2003 Creating Web Pages with HTML, 3e Prepared by: C. Hueckstaedt, Tutorial 8 62 XP Returning a Value from a Function To use a function to calculate a value use the return command along with a variable or value. The following is a example using the Area function: function Area(Width, Length) { var Size = Width*Length; return Size; } the Area function calculates the area of a rectangular

region and places the value in a variable named Size the value of the Size variable is returned by the function Creating Web Pages with HTML, 3e Prepared by: C. Hueckstaedt, Tutorial 8 63 The Area Function XP A simple JavaScript program is: var x = 8; var y = 6; var z = Area(x,y); the first two commands assign the values 8 and 6 to the x and y variables

the values of both of these variables are then sent to the Area function, corresponding to the Width and Length parameters the Area function uses these values to calculate the area, assigning the value to the z variable result is 48, which is assigned to the value of the z variable Creating Web Pages with HTML, 3e Prepared by: C. Hueckstaedt, Tutorial 8 64 XP Placing a Function in an HTML File Where you place a function in the HTML file is important. The function definition must be placed before the command that calls the function.

One programming convention is to place all of the function definitions used between the and tags. A function is executed only when called by another JavaScript command. Creating Web Pages with HTML, 3e Prepared by: C. Hueckstaedt, Tutorial 8 65 XP Placing a Function in an HTML File To use a function on several Web pages, place the function in a separate file and access the function from each Web page. To access the externally located function, insert the following command in the head section of the HTML file:

URL is the filename and location of the external file containing the functions Its common practice for JavaScript programmers to create libraries of functions located in external files. Creating Web Pages with HTML, 3e Prepared by: C. Hueckstaedt, Tutorial 8 66 Setting Date Values XP This figure shows additional JavaScript functions that allow

you to set or change the values of date objects. Creating Web Pages with HTML, 3e Prepared by: C. Hueckstaedt, Tutorial 8 67 The XMASDAYS Function XP This figure show an example of the XMASDAYS function. The function has three variables: XYear: The current year

XDay: The date of Christmas. The initial value of this variable is the date December 25, 2003. DayCount: The number of days between current date and December 25. This is the value that is returned by the function. Creating Web Pages with HTML, 3e Prepared by: C. Hueckstaedt, Tutorial 8 68 Example of Web Page with Days Until Christmas

Creating Web Pages with HTML, 3e Prepared by: C. Hueckstaedt, Tutorial 8 XP 69 XP Working with Conditional Statements A conditional statement is one that runs only when specific conditions are met i.e. If statement. An If statement has the following general syntax: if (condition) { JavaScript Commands } condition is an expression that is either true or false

if the condition is true, the JavaScript Commands in the command block are executed if the condition is not true, then no action is taken Creating Web Pages with HTML, 3e Prepared by: C. Hueckstaedt, Tutorial 8 70 Comparison, Logical, and Conditional Operators XP To create a condition in JavaScript, you need one of three types of operators: comparison operators, logical operators, and conditional operators a comparison operator compares the value of one

element with that of another, which creates a Boolean expression that is either true or false a logical operator connects two or more Boolean expressions a conditional operator tests whether a specific condition is true and returns one value if the condition is true and a different value if the condition is false Creating Web Pages with HTML, 3e Prepared by: C. Hueckstaedt, Tutorial 8 71 XP An Example of Boolean Expressions Here are two examples of Boolean expressions: x < 100;

if x is less than 100, this expression returns the value true; however, if x is 100 or greater, the expression is false y == 20; the y variable must have an exact value of 20 for the expression to be true comparison operator uses a double equal sign (==) rather than a single one (a single equal sign is an assignment operator and is not used for making comparisons) Creating Web Pages with HTML, 3e Prepared by: C. Hueckstaedt, Tutorial 8 72 XP Comparison Operators

This figure lists some of the other comparison operators used in JavaScript. Creating Web Pages with HTML, 3e Prepared by: C. Hueckstaedt, Tutorial 8 73 A Logical Operator XP The logical operator && returns a value of true only if all of the Boolean expressions are true. for example, the following expression is true only if x is less than 100 and y is equal to 20: (x < 100) && (y == 20);

Creating Web Pages with HTML, 3e Prepared by: C. Hueckstaedt, Tutorial 8 74 Logical Operators XP This figure lists some of the logical operators used by JavaScript. Creating Web Pages with HTML, 3e Prepared by: C. Hueckstaedt, Tutorial 8 75 XP

A Conditional Operator A conditional operator tests whether a specific condition is true and returns one value if the condition is true and a different value if the condition is false. for example, the following statement: Message = (mail == Yes) ? You have mail: No mail; tests whether the mail variable is equal to the value Yes if it is, the message variable has the value You have mail; otherwise, the message variable has the value No mail. Creating Web Pages with HTML, 3e Prepared by: C. Hueckstaedt, Tutorial 8 76

Using an If...Else Statement XP The If statement runs a set of commands if the condition is true. To run the If statement for one set of commands if the condition is true and another set of commands if the condition is false use the If...Else statement. The general syntax is: if (condition) { JavaScript Commands if true } else JavaScript Commands if false } condition is an expression that is either true or false, and one set of commands is run if the expression is true, and another is run if the expression is false Creating Web Pages with HTML, 3e

Prepared by: C. Hueckstaedt, Tutorial 8 77 Using an If...Else Conditional Statement XP This figure shows an example of an If...Else conditional statement. Creating Web Pages with HTML, 3e Prepared by: C. Hueckstaedt, Tutorial 8 78 Using Arrays

XP An array is an ordered collection of values referenced by a single variable name. The syntax for creating an array variable is: var variable = new Array(size); variable is the name of the array variable size is the number of elements in the array (optional) Once an array is created, you create values for each individual element in the array. Creating Web Pages with HTML, 3e Prepared by: C. Hueckstaedt, Tutorial 8 79

XP Using Arrays Continued A more efficient way of populating an array is to specify the array contents in the new Array()statement. In this form, the syntax is: var variable = new Array(contents); contents are the array elements enclosed in quotes and separated by commas For example, the following statement creates an array of the names of the seven days of the week: var Wday=new Array(Sun, Mon, Tue, Wed, Thu, Fri, Sat); Creating Web Pages with HTML, 3e Prepared by: C. Hueckstaedt, Tutorial 8 80

XP Creating the MonthTxt Function The MonthTxt function has one parameter, MonthNumber, which is the number of a month that the function uses to return the name of the corresponding month. The figure shows the code for the MonthTxt function.

Creating Web Pages with HTML, 3e Prepared by: C. Hueckstaedt, Tutorial 8 81 Calling the MonthTxt Function XP This figure shows the use of the ThisMonth variable to call the MonthTxt function and then stores the result in a new variable named MonthName.. Creating Web Pages with HTML, 3e Prepared by: C. Hueckstaedt, Tutorial 8 82

Working with Loops XP A program loop is a set of instructions that is executed repeatedly. There are two types of loops: loops that repeat a set number of times before quitting loops that repeat as long as a certain condition is met Creating Web Pages with HTML, 3e Prepared by: C. Hueckstaedt, Tutorial 8 83 XP

The For Loop The For loop allows you to create a group of commands to be executed a set number of times through the use of a counter that tracks the number of times the command block has been run. Set an initial value for the counter, and each time the command block is executed, the counter changes in value. When the counter reaches a value above or below a certain stopping value, the loop ends. Creating Web Pages with HTML, 3e Prepared by: C. Hueckstaedt, Tutorial 8 84 XP

The For Loop Continued The general syntax of the For loop is: for (start; condition; update) { JavaScript Commands } start is the starting value of the counter condition is a Boolean expression that must be true for the loop to continue update specifies how the counter changes in value each time the command block is executed Creating Web Pages with HTML, 3e Prepared by: C. Hueckstaedt, Tutorial 8 85

XP Creating a For Loop This figure shows an example of a For loop used to write a row of table cells. Creating Web Pages with HTML, 3e Prepared by: C. Hueckstaedt, Tutorial 8 86 Nesting a For Loop XP This figure shows code used to write a table containing three rows and four columns. Creating Web Pages with HTML, 3e

Prepared by: C. Hueckstaedt, Tutorial 8 87 Specifying Counter Values in a For Loop XP The For loop is not limited to incrementing the value of the counter by 1. This figure shows examples of other ways of incrementing the counter in a For loop. Creating Web Pages with HTML, 3e Prepared by: C. Hueckstaedt, Tutorial 8 88

XP The While Loop The While loop runs a command group as long as a specific condition is met, but it does not employ any counters. The general syntax of the While loop is: while (condition) { JavaScript Commands } condition is a Boolean expression that can be either true or false Creating Web Pages with HTML, 3e Prepared by: C. Hueckstaedt, Tutorial 8 89

XP Creating a While Loop This figure shows how you can create a set of table cells using a While loop. Creating Web Pages with HTML, 3e Prepared by: C. Hueckstaedt, Tutorial 8 90 Nesting a While Loop XP As with For loops, this figure shows that While loops can be nested inside one another. Creating Web Pages with HTML, 3e

Prepared by: C. Hueckstaedt, Tutorial 8 91 XP Tutorial 8 Summary Discussed JavaScript history and philosophy. Covered the basic features of JavaScript including syntax, operators, expressions and functions. Learned about the

Recently Viewed Presentations

  • New Vector Resonance as an Alternative to Higgs Boson

    New Vector Resonance as an Alternative to Higgs Boson

    Klein-Nishina limit Thomson Klein-Nishina limit (α=1/137) σCompHEP= 2.0899 nb σLEP=1.9993+- 0.0026 nb Tevatron LEP = 0.01627 CompHEP t H g g g t u u d u u d b b p p pp ttH +X tt bb + X...
  • The U.S. Lacey Act: Overview and Recent Developments

    The U.S. Lacey Act: Overview and Recent Developments

    Two necessary components of a Lacey Act violation. An underlying violation of a state, foreign, or tribal law that protects or manages plants and/or derivative products occurs. The tainted good obtained through violation of such a law is traded in...
  • The Medium Access Sublayer - unisi.it

    The Medium Access Sublayer - unisi.it

    Proxy server Summary: Repeaters, Bridges, Routers, Gateways The distinction lies mainly in the "highest" layer at which each operates. Although this terminology is fairly standard, and the preferred common usage, the term "gateway" is sometimes used in the Internet community...
  • OCEN 201 Introduction to Ocean & Coastal Engineering

    OCEN 201 Introduction to Ocean & Coastal Engineering

    Wave direction is normal to shore line. In other words, wave crest-line is parallel to the shore line. Wave Refraction Phenomena of wave shoaling (wave enters from deep water to shallow water) Wave refraction Wave length becomes shorter Wave group...
  • Aucun titre de diapositive

    Aucun titre de diapositive

    Multiflex TPO ER range, based on polyolefin, very high hardness without reinforced mechanical properties. Part II. Multiflex Introduction Multiflex TEA Thermoplastic Elastomer Alloys, including SG range and A range, are compatible with different engineering plastics, which is the most important...
  • 9 things I know now that I wish I knew when I was graduating

    9 things I know now that I wish I knew when I was graduating

    Read articles and books in other disciplines. Many ideas exist in one field that can be very useful in other fields. My personal experiences suggests the need for a modification of the adage "jack of all trades and master of...
  • 2011 ARGOS consortium meeting Australia Blake Orr ARPANSA

    2011 ARGOS consortium meeting Australia Blake Orr ARPANSA

    NPE10. Data from IDC: Seismic events that fall within Possible source region (PSR) The starting point of the assessment of NPE10 exercise was the Data Fusion Bulletins posted on the IDC web-site.
  • Glass Fractures - bsapp.com

    Glass Fractures - bsapp.com

    Link a suspect to a crime scene Fingerprints Blood Fractures Direction of Penetration A projectile hole is inevitably wider at the exit side Direction of Penetration Stress Marks Successive Penetrations A fracture always terminates at an existing line of fracture...