Presentation is loading. Please wait.

Presentation is loading. Please wait.

Internet & World Wide Web How to Program, 5/e ©1992-2012 by Pearson Education, Inc. All Rights Reserved.

Similar presentations


Presentation on theme: "Internet & World Wide Web How to Program, 5/e ©1992-2012 by Pearson Education, Inc. All Rights Reserved."— Presentation transcript:

1 Internet & World Wide Web How to Program, 5/e ©1992-2012 by Pearson Education, Inc. All Rights Reserved.

2

3

4  JavaScript  Scripting language which is used to enhance the functionality and appearance of web pages. ©1992-2012 by Pearson Education, Inc. All Rights Reserved.

5  We begin with a simple script that displays the text "Welcome to JavaScript Programming!" in the HTML5 document.  All major web browsers contain JavaScript interpreters, which process the commands written in JavaScript. . ©1992-2012 by Pearson Education, Inc. All Rights Reserved.

6

7

8  Often, JavaScripts appear in the section of the HTML5 document  The browser interprets the contents of the section first  The tag indicates to the browser that the text that follows is part of a script.  Attribute type specifies the scripting language used in the script—such as text/javascript ©1992-2012 by Pearson Education, Inc. All Rights Reserved.

9  A string of characters can be contained between double quotation ( " ) marks (also called a string literal) ©1992-2012 by Pearson Education, Inc. All Rights Reserved.

10  Every statement should end with a semicolon (;) (also known as the statement terminator), although none is required by JavaScript  JavaScript is case sensitive  Not using the proper uppercase and lowercase letters is a syntax error ©1992-2012 by Pearson Education, Inc. All Rights Reserved.

11  The document object’s writeln method  Writes a line of HTML5 text in the HTML5 document ©1992-2012 by Pearson Education, Inc. All Rights Reserved.

12  Method write displays a string like writeln, but does not position the output cursor in the HTML5 document at the beginning of the next line after writing its argument ©1992-2012 by Pearson Education, Inc. All Rights Reserved.

13

14

15  The + operator (called the “concatenation operator” when used in this manner) joins two strings together ©1992-2012 by Pearson Education, Inc. All Rights Reserved.

16 Displaying Text in an Alert Dialog  Dialogs  Useful to display information in windows that “pop up” on the screen to grab the user’s attention  Typically used to display important messages to the user browsing the web page  Browser’s window object uses method alert to display an alert dialog  Method alert requires as its argument the string to be displayed ©1992-2012 by Pearson Education, Inc. All Rights Reserved.

17

18

19

20  Scripting  Gives you the ability to generate part or all of a web page’s content at the time it is shown to the user ©1992-2012 by Pearson Education, Inc. All Rights Reserved.

21  The next script creates a dynamic welcome page that obtains the user’s name, then displays it on the page.  The script uses another predefined dialog box from the window object—a prompt dialog—which allows the user to enter a value that the script can use.   Figure 6.5 presents the script and sample output. ©1992-2012 by Pearson Education, Inc. All Rights Reserved.

22

23

24  Keywords are words with special meaning in JavaScript  Keyword var  Used to declare the names of variables  A variable is a location in the computer’s memory where a value can be stored for use by a script  All variables have a name, type and value, and should be declared with a var statement before they are used in a script ©1992-2012 by Pearson Education, Inc. All Rights Reserved.

25  Declarations end with a semicolon ( ; )  Several variables may be declared in one declaration or in multiple declarations.  Comments  A single-line comment begins with the characters // and terminates at the end of the line  Comments do not cause the browser to perform any action when the script is interpreted; rather, comments are ignored by the JavaScript interpreter  Multiline comments begin with delimiter /* and end with delimiter */  All text between the delimiters of the comment is ignored by the interpreter. ©1992-2012 by Pearson Education, Inc. All Rights Reserved.

26

27  A variable is assigned a value with an assignment statement, using the assignment operator, =.  The = operator is called a binary operator, because it has two operands. ©1992-2012 by Pearson Education, Inc. All Rights Reserved.

28  null keyword  Signifies that a variable has no value  Function parseInt  converts its string argument to an integer ©1992-2012 by Pearson Education, Inc. All Rights Reserved.

29  Figure 6.7 inputs two integers (whole numbers, such as 7, –11, 0 and 31914) typed by a user at the keyboard, computes the sum of the values and displays the result. ©1992-2012 by Pearson Education, Inc. All Rights Reserved.

30

31

32

33  Variable names correspond to locations in the computer’s memory.  Every variable has a name, a type and a value.  When a value is placed in a memory location, the value replaces the previous value in that location. ©1992-2012 by Pearson Education, Inc. All Rights Reserved.

34

35

36

37  JavaScript does not require variables to have a type before they can be used in a script  A variable in JavaScript can contain a value of any data type, and in many situations, JavaScript automatically converts between values of different types for you  When a variable is declared in JavaScript, but is not given a value, it has an undefined value. default  When variables are declared, they are not assigned default values, unless specified otherwise by the programmer. ©1992-2012 by Pearson Education, Inc. All Rights Reserved.

38  The basic arithmetic operators ( +, -, *, /, and % ) are binary operators, because they each operate on two operands  JavaScript provides the remainder operator, %, which yields the remainder after division ©1992-2012 by Pearson Education, Inc. All Rights Reserved.

39

40  if statement allows a script to make a decision based on the truth or falsity of a condition  If the condition is met (i.e., the condition is true ), the statement in the body of the if statement is executed  If the condition is not met (i.e., the condition is false ), the statement in the body of the if statement is not executed  Conditions in if statements can be formed by using the equality operators and relational operators ©1992-2012 by Pearson Education, Inc. All Rights Reserved.

41

42  Any computable problem can be solved by executing a series of actions in a specific order  A procedure for solving a problem in terms of  the actions to be executed, and  the order in which the actions are to be executed is called an algorithm ©1992-2010 by Pearson Education, Inc. All Rights Reserved.

43  Pseudocode informal language  An informal language that helps you develop algorithms  Pseudocode is similar to everyday English; it’s convenient and user friendly, although it’s not an actual computer programming language ©1992-2010 by Pearson Education, Inc. All Rights Reserved.

44  Sequential execution  Execute statements in the order they appear in the code  Transfer of control  Changing the order in which statements execute  All scripts can be written in terms of only three control statements  sequence  selection  repetition ©1992-2010 by Pearson Education, Inc. All Rights Reserved.

45

46  Flowchart graphical representation of an algorithm  A graphical representation of an algorithm or of a portion of an algorithm ©1992-2010 by Pearson Education, Inc. All Rights Reserved.

47  JavaScript provides three selection structures.  The if statement either performs (selects) an action if a condition is true or skips the action if the condition is false. single-selection  Called a single-selection statement because it selects or ignores a single action or group of actions.  The if…else statement performs an action if a condition is true and performs a different action if the condition is false.  Double-selection  Double-selection statement because it selects between two different actions or group of actions.  The switch statement performs one of many different actions, depending on the value of an expression.  Multiple-selection  Multiple-selection statement because it selects among many different actions or groups of actions. ©1992-2010 by Pearson Education, Inc. All Rights Reserved.

48  JavaScript provides four repetition statements, namely, while, do … while, for and for … in.  In addition to keywords, JavaScript has other words that are reserved for use by the language, such as the values null, true and false, and words that are reserved for possible future use. ©1992-2010 by Pearson Education, Inc. All Rights Reserved.

49

50

51  A logic error has its effect at execution time.  A fatal logic error causes a script to fail and terminate prematurely.  A nonfatal logic error allows a script to continue executing, but the script produces incorrect results. ©1992-2010 by Pearson Education, Inc. All Rights Reserved.

52  while while some condition remains  Allows you to specify that an action is to be repeated while some condition remains true  The body of a loop may be a single statement or a block  Eventually, the condition becomes false and repetition terminates ©1992-2010 by Pearson Education, Inc. All Rights Reserved.

53

54  Counter-controlled repetition  Often called definite repetition, because the number of repetitions is known before the loop begins executing  A counter is a variable a script uses to count—typically in a repetition statement ©1992-2010 by Pearson Education, Inc. All Rights Reserved.

55

56

57

58

59

60  Sentinel-controlled repetition  Special value called a sentinel) indicates the end of data entry  Often is called indefinite repetition, because the number of repetitions is not known in advance  Choose a sentinel value that cannot be confused with an acceptable input value ©1992-2010 by Pearson Education, Inc. All Rights Reserved.

61

62

63

64

65

66  Control structures may be nested inside of one another ©1992-2010 by Pearson Education, Inc. All Rights Reserved.

67

68

69

70

71

72

73


Download ppt "Internet & World Wide Web How to Program, 5/e ©1992-2012 by Pearson Education, Inc. All Rights Reserved."

Similar presentations


Ads by Google