Chapter 2 Murach's JavaScript and jQuery, C2© 2012, Mike Murach & Associates, Inc.Slide 1
Objectives Murach's JavaScript and jQuery, C2© 2012, Mike Murach & Associates, Inc. Slide 2
Objectives (continued) Murach's JavaScript and jQuery, C2© 2012, Mike Murach & Associates, Inc. Slide 3
Objectives (continued) Murach's JavaScript and jQuery, C2© 2012, Mike Murach & Associates, Inc. Slide 4
Two attributes of the script element Murach's JavaScript and jQuery, C2© 2012, Mike Murach & Associates, Inc. Slide 5
A script element that embeds JavaScript in the head section Murach's JavaScript and jQuery, C2© 2012, Mike Murach & Associates, Inc. Slide 6
Terms Murach's JavaScript and jQuery, C2© 2012, Mike Murach & Associates, Inc. Slide 7
JavaScript in the body of an HTML document Murach's JavaScript and jQuery, C2© 2012, Mike Murach & Associates, Inc. Slide 8
The result of the JavaScript in a web browser Murach's JavaScript and jQuery, C2© 2012, Mike Murach & Associates, Inc. Slide 9
A noscript element in the body of the HTML Murach's JavaScript and jQuery, C2© 2012, Mike Murach & Associates, Inc. Slide 10
A block of JavaScript code Murach's JavaScript and jQuery, C2© 2012, Mike Murach & Associates, Inc. Slide 11
The basic syntax rules for JavaScript Murach's JavaScript and jQuery, C2© 2012, Mike Murach & Associates, Inc. Slide 12
How to split a statement over two or more lines Murach's JavaScript and jQuery, C2© 2012, Mike Murach & Associates, Inc. Slide 13
Rules for creating identifiers Murach's JavaScript and jQuery, C2© 2012, Mike Murach & Associates, Inc. Slide 14
Valid identifiers in JavaScript Murach's JavaScript and jQuery, C2© 2012, Mike Murach & Associates, Inc. Slide 15
Camel casing versus underscore notation Murach's JavaScript and jQuery, C2© 2012, Mike Murach & Associates, Inc. Slide 16
Naming recommendations Murach's JavaScript and jQuery, C2© 2012, Mike Murach & Associates, Inc. Slide 17
JavaScript code that includes comments Murach's JavaScript and jQuery, C2© 2012, Mike Murach & Associates, Inc. Slide 18
The syntax rules for JavaScript comments Murach's JavaScript and jQuery, C2© 2012, Mike Murach & Associates, Inc. Slide 19
Guidelines for using comments Murach's JavaScript and jQuery, C2© 2012, Mike Murach & Associates, Inc. Slide 20
Terms Murach's JavaScript and jQuery, C2© 2012, Mike Murach & Associates, Inc. Slide 21
Common methods of the window object Murach's JavaScript and jQuery, C2© 2012, Mike Murach & Associates, Inc. Slide 22
A statement that calls the prompt method with the object name omitted Murach's JavaScript and jQuery, C2© 2012, Mike Murach & Associates, Inc. Slide 23
One property of the window object Murach's JavaScript and jQuery, C2© 2012, Mike Murach & Associates, Inc. Slide 24
Terms related to objects Murach's JavaScript and jQuery, C2© 2012, Mike Murach & Associates, Inc. Slide 25
Number, string, and Boolean values Murach's JavaScript and jQuery, C2© 2012, Mike Murach & Associates, Inc. Slide 26
Terms related to data types Murach's JavaScript and jQuery, C2© 2012, Mike Murach & Associates, Inc. Slide 27
Common arithmetic operators Murach's JavaScript and jQuery, C2© 2012, Mike Murach & Associates, Inc. Slide 28
The order of precedence for arithmetic expressions Murach's JavaScript and jQuery, C2© 2012, Mike Murach & Associates, Inc. Slide 29
Terms related to numeric expressions Murach's JavaScript and jQuery, C2© 2012, Mike Murach & Associates, Inc. Slide 30
The most useful assignment operators Murach's JavaScript and jQuery, C2© 2012, Mike Murach & Associates, Inc. Slide 31
How to code compound assignment statements Murach's JavaScript and jQuery, C2© 2012, Mike Murach & Associates, Inc. Slide 32
Three ways to increment a counter variable Murach's JavaScript and jQuery, C2© 2012, Mike Murach & Associates, Inc. Slide 33
A floating-point result that isn’t precise Murach's JavaScript and jQuery, C2© 2012, Mike Murach & Associates, Inc. Slide 34
Terms for working with variables Murach's JavaScript and jQuery, C2© 2012, Mike Murach & Associates, Inc. Slide 35
The concatenation operator for strings Murach's JavaScript and jQuery, C2© 2012, Mike Murach & Associates, Inc. Slide 36
Escape sequences that can be used in strings Murach's JavaScript and jQuery, C2© 2012, Mike Murach & Associates, Inc. Slide 37
How to declare string variables Murach's JavaScript and jQuery, C2© 2012, Mike Murach & Associates, Inc. Slide 38
How to code compound assignment statements Murach's JavaScript and jQuery, C2© 2012, Mike Murach & Associates, Inc. Slide 39
How escape sequences can be used in a string Murach's JavaScript and jQuery, C2© 2012, Mike Murach & Associates, Inc. Slide 40
How to declare Boolean variables and assign values to them Murach's JavaScript and jQuery, C2© 2012, Mike Murach & Associates, Inc. Slide 41
Terms for string expressions Murach's JavaScript and jQuery, C2© 2012, Mike Murach & Associates, Inc. Slide 42
How JavaScript interprets the plus sign in mixed expressions Murach's JavaScript and jQuery, C2© 2012, Mike Murach & Associates, Inc. Slide 43
Two methods of the window object for converting string values Murach's JavaScript and jQuery, C2© 2012, Mike Murach & Associates, Inc. Slide 44
The same examples with chaining Murach's JavaScript and jQuery, C2© 2012, Mike Murach & Associates, Inc. Slide 45
Terms Murach's JavaScript and jQuery, C2© 2012, Mike Murach & Associates, Inc. Slide 46
The relational operators Murach's JavaScript and jQuery, C2© 2012, Mike Murach & Associates, Inc. Slide 47
The syntax of the global isNaN method Murach's JavaScript and jQuery, C2© 2012, Mike Murach & Associates, Inc. Slide 48
The logical operators in order of precedence Murach's JavaScript and jQuery, C2© 2012, Mike Murach & Associates, Inc. Slide 49
Terms for conditional expressions Murach's JavaScript and jQuery, C2© 2012, Mike Murach & Associates, Inc. Slide 50
The syntax of the if statement Murach's JavaScript and jQuery, C2© 2012, Mike Murach & Associates, Inc. Slide 51
An if statement with else if and else clauses Murach's JavaScript and jQuery, C2© 2012, Mike Murach & Associates, Inc. Slide 52
An if statement with a compound conditional expression Murach's JavaScript and jQuery, C2© 2012, Mike Murach & Associates, Inc. Slide 53
How to test a Boolean variable Murach's JavaScript and jQuery, C2© 2012, Mike Murach & Associates, Inc. Slide 54
The syntax of a while loop Murach's JavaScript and jQuery, C2© 2012, Mike Murach & Associates, Inc. Slide 55
The syntax of a do-while loop Murach's JavaScript and jQuery, C2© 2012, Mike Murach & Associates, Inc. Slide 56
A while loop that gets the average of numbers Murach's JavaScript and jQuery, C2© 2012, Mike Murach & Associates, Inc. Slide 57
The syntax of a for statement Murach's JavaScript and jQuery, C2© 2012, Mike Murach & Associates, Inc. Slide 58
A for loop that calculates future value Murach's JavaScript and jQuery, C2© 2012, Mike Murach & Associates, Inc. Slide 59
Terms for conditional statements Murach's JavaScript and jQuery, C2© 2012, Mike Murach & Associates, Inc. Slide 60
The Calculate MPG application Murach's JavaScript and jQuery, C2© 2012, Mike Murach & Associates, Inc. Slide 61
The Calculate MPG application (continued) Murach's JavaScript and jQuery, C2© 2012, Mike Murach & Associates, Inc. Slide 62
The HTML and JavaScript for the application Murach's JavaScript and jQuery, C2© 2012, Mike Murach & Associates, Inc. Slide 63
The dialog boxes for the Test Scores application Murach's JavaScript and jQuery, C2© 2012, Mike Murach & Associates, Inc. Slide 64
The Test Scores application (continued) Murach's JavaScript and jQuery, C2© 2012, Mike Murach & Associates, Inc. Slide 65
The JavaScript in the HTML head section Murach's JavaScript and jQuery, C2© 2012, Mike Murach & Associates, Inc. Slide 66
The Firefox Error Console with an error Murach's JavaScript and jQuery, C2© 2012, Mike Murach & Associates, Inc. Slide 67
How to display the Firefox Error Console and the source code for an error Murach's JavaScript and jQuery, C2© 2012, Mike Murach & Associates, Inc. Slide 68
Common syntax errors Murach's JavaScript and jQuery, C2© 2012, Mike Murach & Associates, Inc. Slide 69
Extra 2-1: Convert number grades to letter grades Murach's JavaScript and jQuery, C2© 2012, Mike Murach & Associates, Inc. Slide 70
Extra 2-1: (continued) Murach's JavaScript and jQuery, C2© 2012, Mike Murach & Associates, Inc. Slide 71
Extra 2-2: Convert Fahrenheit to Celsius Murach's JavaScript and jQuery, C2© 2012, Mike Murach & Associates, Inc. Slide 72
Extra 2-3:Calculate income tax Murach's JavaScript and jQuery, C2© 2012, Mike Murach & Associates, Inc. Slide 73
Extra 2-3: (continued) Murach's JavaScript and jQuery, C2© 2012, Mike Murach & Associates, Inc. Slide 74
Short 2-1: Enhance the Test Scores application Murach's JavaScript and jQuery, C2© 2012, Mike Murach & Associates, Inc. Slide 75