Part:2.  Keywords are words with special meaning in JavaScript  Keyword var ◦ Used to declare the names of variables ◦ A variable is a location in the.

Slides:



Advertisements
Similar presentations
/ 251 Internet Applications Ahmed M. Zeki Sem – / Chapter 8.
Advertisements

Chapter 2 Part B CISS 241. Take a few moments and work with another student to develop an algorithm for a program that will add two whole numbers (integers)
Lecture 2 Introduction to C Programming
Introduction to C Programming
CS 6301 Lecture 2: First Program1. CS Topics of this lecture Introduce first program  Explore inputs and outputs of a program Arithmetic using.
1 Chapter 2 Introduction to Java Applications Introduction Java application programming Display ____________________ Obtain information from the.
Chapter 2 Introduction to C Programming
 2000 Prentice Hall, Inc. All rights reserved. Chapter 2 - Introduction to C Programming Outline 2.1Introduction 2.2A Simple C Program: Printing a Line.
Introduction to C Programming
1 Outline 13.1Introduction 13.2A Simple Program: Printing a Line of Text in a Web Page 13.3Another JavaScript Program: Adding Integers 13.4Memory Concepts.
 2008 Pearson Education, Inc. All rights reserved JavaScript: Introduction to Scripting.
Introduction to scripting
CSCI 1730 January 17 th, 2012 © by Pearson Education, Inc. All Rights Reserved.
 2003 Prentice Hall, Inc. All rights reserved. 1 Introduction to C++ Programming Outline Introduction to C++ Programming A Simple Program: Printing a.
 2004 Prentice Hall, Inc. All rights reserved. Chapter 7 - JavaScript: Introduction to Scripting Outline 7.1 Introduction 7.2 Simple Program: Printing.
WEB DESIGN AND PROGRAMMING Introduction to Javascript.
 2003 Prentice Hall, Inc. All rights reserved. CHAPTER 3 JavaScript 1.
Java™ How to Program, 9/e © Copyright by Pearson Education, Inc. All Rights Reserved.
Android How to Program, 2/e © Copyright by Pearson Education, Inc. All Rights Reserved.
 2001 Prentice Hall, Inc. All rights reserved. 1 Chapter 7 - JavaScript: Introduction to Scripting Outline 7.1 Introduction 7.2 Simple Program: Printing.
Internet & World Wide Web How to Program, 5/e © by Pearson Education, Inc. All Rights Reserved.
 2008 Pearson Education, Inc. All rights reserved JavaScript: Introduction to Scripting.
 2008 Pearson Education, Inc. All rights reserved JavaScript: Introduction to Scripting.
 2008 Pearson Education, Inc. All rights reserved JavaScript: Introduction to Scripting.
 2003 Prentice Hall, Inc. All rights reserved. CHAPTER 3 JavaScript 1.
C How to Program, 7/e © by Pearson Education, Inc. All Rights Reserved.
Ch 6: JavaScript Introduction to scripting part 2.
© Copyright 1992–2004 by Deitel & Associates, Inc. and Pearson Education Inc. All Rights Reserved. Chapter 2 Chapter 2 - Introduction to C Programming.
C++ How to Program, 8/e © by Pearson Education, Inc. All Rights Reserved.
 Pearson Education, Inc. All rights reserved Introduction to Java Applications.
C++ How to Program, Late Objects Version, 7/e © by Pearson Education, Inc. All Rights Reserved.
Dr. Qusai Abuein1 Internet & WWW How to program Chap.(6) JavaScript:Introduction to Scripting.
Internet & World Wide Web How to Program, 5/e © by Pearson Education, Inc. All Rights Reserved.
 2000 Deitel & Associates, Inc. All rights reserved. Outline 8.1Introduction 8.2A Simple Program: Printing a Line of Text in a Web Page 8.3Another JavaScript.
Internet & World Wide Web How to Program, 5/e © by Pearson Education, Inc. All Rights Reserved.
 2008 Pearson Education, Inc. All rights reserved JavaScript: Introduction to Scripting.
 2008 Pearson Education, Inc. All rights reserved JavaScript: Introduction to Scripting.
JavaScript 1 COE 201- Computer Proficiency. Introduction JavaScript scripting language ▫Originally created by Netscape ▫Facilitates disciplined approach.
Internet & World Wide Web How to Program, 5/e © by Pearson Education, Inc. All Rights Reserved.
 2003 Prentice Hall, Inc. All rights reserved. Chapter 7 - JavaScript: Introduction to Scripting Outline 7.1 Introduction 7.2 Simple Program: Printing.
 2008 Pearson Education, Inc. All rights reserved JavaScript: Introduction to Scripting.
© Copyright 1992–2004 by Deitel & Associates, Inc. and Pearson Education Inc. All Rights Reserved. 1 Chapter 2 - Introduction to C Programming Outline.
 2007 Pearson Education, Inc. All rights reserved. A Simple C Program 1 /* ************************************************* *** Program: hello_world.
Internet & World Wide Web How to Program, 5/e © by Pearson Education, Inc. All Rights Reserved.
 Most C programs perform calculations using the C arithmetic operators (Fig. 2.9).  Note the use of various special symbols not used in algebra.  The.
 2003 Prentice Hall, Inc. All rights reserved Basics of a Typical C++ Environment C++ systems –Program-development environment –Language –C++
REEM ALMOTIRI Information Technology Department Majmaah University.
 2008 Pearson Education, Inc. All rights reserved JavaScript: Introduction to Scripting.
 2008 Pearson Education, Inc. All rights reserved JavaScript: Introduction to Scripting.
1 Lecture 2 - Introduction to C Programming Outline 2.1Introduction 2.2A Simple C Program: Printing a Line of Text 2.3Another Simple C Program: Adding.
Chapter 6 JavaScript: Introduction to Scripting
ARITHMETIC IN C Operators.
2.5 Another Java Application: Adding Integers
JavaScript: Introduction to Scripting
Chapter 13 - JavaScript/JScript: Introduction to Scripting
Introduction to Scripting
Chapter 7 - JavaScript: Introduction to Scripting
Introduction to C++ Programming
JavaScript: Introduction to Scripting
WEB PROGRAMMING JavaScript.
JavaScript: Introduction to Scripting
JavaScript: Introduction to Scripting
JavaScript: Introduction to Scripting
Chapter 7 - JavaScript: Introduction to Scripting
Chapter 7 - JavaScript: Introduction to Scripting
JavaScript: Introduction to Scripting
Chapter 2, Part III Arithmetic Operators and Decision Making
C How to Program, 6/e © by Pearson Education, Inc. All Rights Reserved.
Chapter 7 - JavaScript: Introduction to Scripting
Presentation transcript:

Part:2

 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  A variable name can be any valid identifier consisting of letters, digits, underscores ( _ ) and dollar signs ( $ ) that does not begin with a digit and is not a reserved JavaScript keyword. © by Pearson Education, Inc. All Rights Reserved.

 Declarations end with a semicolon ( ; ) and can be split over several lines, with each variable in the declaration separated by a comma (forming a comma-separated list of variable names) ◦ 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. © by Pearson Education, Inc. All Rights Reserved.

 The window object’s prompt method displays a dialog into which the user can type a value. ◦ The first argument is a message (called a prompt) that directs the user to take a specific action. ◦ The optional second argument is the default string to display in the text field.  Script can then use the value that the user inputs. © by Pearson Education, Inc. All Rights Reserved.

 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. © by Pearson Education, Inc. All Rights Reserved.

 null keyword ◦ Signifies that a variable has no value ◦ null is not a string literal, but rather a predefined term indicating the absence of value ◦ Writing a null value to the document, however, displays the word “ null ”  Function parseInt ◦ converts its string argument to an integer  JavaScript has a version of the + operator for string concatenation that enables a string and a value of another data type (including another string) to be concatenated © by Pearson Education, Inc. All Rights Reserved.

 Our next script illustrates another use of prompt dialogs to obtain input from the user.  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. © by Pearson Education, Inc. All Rights Reserved.

 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. © by Pearson Education, Inc. All Rights Reserved.

 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.  When variables are declared, they are not assigned default values, unless specified otherwise by the programmer. ◦ To indicate that a variable does not contain a value, you can assign the value null to it. © by Pearson Education, Inc. All Rights Reserved.

 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  Arithmetic expressions in JavaScript must be written in straight-line form to facilitate entering programs into the computer © by Pearson Education, Inc. All Rights Reserved.

 Parentheses can be used to group expressions as in algebra.  sequence determined by the rules of operator precedence: ◦ Multiplication, division and remainder operations are applied first. ◦ If an expression contains several of these operations, operators are applied from left to right. ◦ Multiplication, division and remainder operations are said to have the same level of precedence. ◦ Addition and subtraction operations are applied next. ◦ If an expression contains several of these operations, operators are applied from left to right. ◦ Addition and subtraction operations have the same level of precedence. © by Pearson Education, Inc. All Rights Reserved.

 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 © by Pearson Education, Inc. All Rights Reserved.

 Equality operators both have the same level of precedence, which is lower than the precedence of the relational operators.  The equality operators associate from left to right. © by Pearson Education, Inc. All Rights Reserved.

 The script in Fig uses four if statements to display a time-sensitive greeting on a welcome page. © by Pearson Education, Inc. All Rights Reserved.

 Date object ◦ Used acquire the current local time ◦ Create a new instance of an object by using the new operator followed by the type of the object, Date, and a pair of parentheses © by Pearson Education, Inc. All Rights Reserved.