Ch 6: JavaScript Introduction to scripting part 2.

Slides:



Advertisements
Similar presentations
 2001 Prentice Hall, Inc. All rights reserved. 1 Chapter 7 - JavaScript: Introduction to Scripting Outline 7.1 Introduction 7.2 Simple Program: Printing.
Advertisements

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.
 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.
 2007 Pearson Education, Inc. All rights reserved Introduction to C Programming.
Introduction to C Programming
Introduction to scripting
Chapter 01: Introduction to Computer Programming
 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.
 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.
© Copyright 1992–2004 by Deitel & Associates, Inc. and Pearson Education Inc. All Rights Reserved. Chapter 2 Chapter 2 - Introduction to C Programming.
Introduction to C Programming Angela Chih-Wei Tang ( 唐 之 瑋 ) Department of Communication Engineering National Central University JhongLi, Taiwan 2010 Fall.
Lecture 2: Introduction to C Programming. OBJECTIVES In this lecture you will learn:  To use simple input and output statements.  The fundamental data.
Introduction to Visual Basic Programming. Introduction Simple Program: Printing a Line of Text Another Simple Program: Adding Integers Memory Concepts.
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.
 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.
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.
 2003 Prentice Hall, Inc. All rights reserved. Chapter 7 - JavaScript: Introduction to Scripting Outline 7.1 Introduction 7.2 Simple Program: Printing.
Chapter 7 - JavaScript: Introduction to Scripting Outline 7.1 Introduction 7.2 Simple Program: Printing a Line of Text in a Web Page 7.3 Another JavaScript.
 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.
Adapted from  2004 Prentice Hall, Inc. All rights reserved. 5 th and 4 th ed: Chapters 6,7,8 SY306 Web and Databases for Cyber Operations SlideSet #6:
 2007 Pearson Education, Inc. All rights reserved. A Simple C Program 1 /* ************************************************* *** Program: hello_world.
1 CISC181 Introduction to Computer Science Dr. McCoy Lecture 2 September 3, 2009.
Internet & World Wide Web How to Program, 5/e © by Pearson Education, Inc. All Rights Reserved.
 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.
 2001 Prentice Hall, Inc. All rights reserved. Outline 1 JavaScript.
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
Chapter 2 - Introduction to C Programming
Chapter 2 - Introduction to C Programming
Introduction to C++ Programming
JavaScript: Introduction to Scripting
WEB PROGRAMMING JavaScript.
Chapter 2 - Introduction to C Programming
JavaScript: Introduction to Scripting
Chapter 2 - Introduction to C Programming
JavaScript: Introduction to Scripting
Chapter 7 - JavaScript: Introduction to Scripting
Chapter 2 - Introduction to C Programming
JavaScript: Introduction to Scripting
Chapter 7 - JavaScript: Introduction to Scripting
Chapter 7 - JavaScript: Introduction to Scripting
JavaScript: Introduction to Scripting
Chapter 7 - JavaScript: Introduction to Scripting
Presentation transcript:

Ch 6: JavaScript Introduction to scripting part 2

6.4 Obtaining User Input with prompt Dialogs <!-- var firstNumber; //string for storing first input var secondNumber; //string for storing second input var num1; //integer for storing first input var num2; //integer for storing second input var sum; firstNumber = window.prompt(“Enter the First number”); secondNumber = window.prompt(“Enter the Second number”); num1 = parseInt(firstNumber); num2 = parseInt(secondNumber); sum = num1 + num2; document.writeln(“ The sum is” + sum + “ ”); // --> Click Refresh (or Reload) to run this script again.

6.4 Obtaining User Input with prompt Dialogs

4 6.5 Memory Concepts 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. When a value is read out of a memory location, the process is nondestructive.

5 6.5 Memory Concepts (Cont.) JavaScript does not require variables to have a type before they can be used in a program 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 JavaScript is referred to as a loosely typed language When a variable is declared in JavaScript, but is not given a value, it has an undefined value. Attempting to use the value of such a variable is normally a logic error. To indicate that a variable does not contain a value, you can assign the value null to it.

6 6.6 Arithmetic The basic arithmetic operators ( +, -, *, /, and % ) are binary operators, because they each operate on two operands JavaScript provides the remainder (modulus) operator, %, which yields the remainder after division

7 Fig | Arithmetic operators.

8 Fig | Precedence of arithmetic operators.

9 Fig | Order in which a second-degree polynomial is evaluated.

Decision Making: Equality and Relational Operators if statement allows a program 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

11 Fig | Equality and relational operators.

Decision Making: Equality and Relational Operators (Cont.) 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

6.7 Decision Making: Equality and Relational Operators (Cont.) <!-- var name; var now = new Date(); //current date and time var hour = now.getHours(); //current hour (0-23) name = window.prompt(“Please enter your name”); if(hour<12) // if it is in the morning document.write(“ Good morning, ”); if(hour >= 12) // if it is in the afternoon { //convert hour to 12-hour system hour = hour – 12; if(hour < 6) // if it is before 6 pm document.write(“ Good afternoon, “); if(hour >= 6) //if it is after 6 pm document.write(“ Good evening, “); } //end if document.writeln( name + “Welcome to JavaScript Programming! ”); // -->