1 Chapter 3 – JavaScript Outline Introduction Flowcharts Control Structures if Selection Structure if/else Selection Structure while Repetition Structure.

Slides:



Advertisements
Similar presentations
Chapter 7 JavaScript: Introduction to Scripting. Outline Simple Programs Objects and Variables Obtaining User Input with prompt Dialogs – –Dynamic Welcome.
Advertisements

Types of selection structures
 2001 Prentice Hall, Inc. All rights reserved. 1 Chapter 7 - JavaScript: Introduction to Scripting Outline 7.1 Introduction 7.2 Simple Program: Printing.
The Web Warrior Guide to Web Design Technologies
Outline IS400: Development of Business Applications on the Internet Fall 2004 Instructor: Dr. Boris Jukic JavaScript: Introduction to Scripting.
Java review and more. Class Header  Public class Welcome  Case sensitive  Body of the class must be enclosed by braces.
 2002 Prentice Hall. All rights reserved. 1 Outline 4.1 Introduction 4.2 Algorithms 4.3 Pseudocode 4.4 Control Structures 4.5 The if Selection Structure.
 2001 Deitel & Associates, Inc. All rights reserved. 1 Outline 14.1Introduction 14.2Algorithms 14.3Pseudocode 14.4Control Structures 14.5The if Selection.
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.
Information Technology Center Hany Abdelwahab Computer Specialist.
Introduction to JavaScript for Python Programmers
Introduction to JavaScript. Aim To enable you to write you first JavaScript.
Introduction to scripting
4.1 JavaScript Introduction
 2001 Prentice Hall, Inc. All rights reserved. 1 Chapter 8 - JavaScript: Control Structures I Outline 8.1 Introduction 8.2 Algorithms 8.3 Pseudocode 8.4.
JavaScript: Control Structures September 27, 2005 Slides modified from Internet & World Wide Web: How to Program (3rd) edition. By Deitel, Deitel,
 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.
CS346 - Javascript 1, 21 Module 1 Introduction to JavaScript CS346.
 2003 Prentice Hall, Inc. All rights reserved. CHAPTER 3 JavaScript 1.
© 2000 – All Rights Reserved - Page 1 Introduction to JavaScript Programming Part Two.
 2001 Prentice Hall, Inc. All rights reserved. 1 Chapter 7 - JavaScript: Introduction to Scripting Outline 7.1 Introduction 7.2 Simple Program: Printing.
Section 17.1 Add an audio file using HTML Create a form using HTML Add text boxes using HTML Add radio buttons and check boxes using HTML Add a pull-down.
INTRODUCTION TO JAVASCRIPT AND DOM Internet Engineering Spring 2012.
 2008 Pearson Education, Inc. All rights reserved JavaScript: Introduction to Scripting.
Using Client-Side Scripts to Enhance Web Applications 1.
 2003 Prentice Hall, Inc. All rights reserved. CHAPTER 3 JavaScript 1.
JavaScript - A Web Script Language Fred Durao
1 Outline 4.1 Introduction 4.2 Algorithms 4.3 Pseudocode 4.4 Control Structures 4.5 The if Selection Structure 4.6 The if / else Selection Structure 4.7.
 2001 Prentice Hall, Inc. All rights reserved. 1 Chapter 17 - WMLScript: Control Structures I Outline 17.1 Introduction 17.2 Algorithms 17.3 Pseudocode.
 2001 Prentice Hall, Inc. All rights reserved. 1 Chapter 8 - JavaScript: Control Structures I Outline 8.1 Introduction 8.2 Algorithms 8.3 Pseudocode 8.4.
Dr. Qusai Abuein1 Internet & WWW How to program Chap.(6) JavaScript:Introduction to Scripting.
Input & Output Functions JavaScript is special from other languages because it can accept input and produce output on the basis of that input in the same.
1 JavaScript: Control Structures. 2 Control Structures Flowcharting JavaScript’s sequence structure.
Chapter 2: Variables, Functions, Objects, and Events JavaScript - Introductory.
 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.
JavaScript Introduction.  JavaScript is a scripting language  A scripting language is a lightweight programming language  A JavaScript can be inserted.
 2008 Pearson Education, Inc. All rights reserved JavaScript: Introduction to Scripting.
 2002 Prentice Hall. All rights reserved. 1 Chapter 4 – Control Structures Part 1 Outline 4.1 Introduction 4.2 Algorithms 4.3 Pseudocode 4.4 Control Structures.
1 CSC160 Chapter 7: Events and Event Handlers. 2 Outline Event and event handlers onClick event handler onMouseOver event handler onMouseOut event handler.
HTML Overview Part 5 – JavaScript 1. Scripts 2  Scripts are used to add dynamic content to a web page.  Scripts consist of a list of commands that execute.
JavaScript 1 COE 201- Computer Proficiency. Introduction JavaScript scripting language ▫Originally created by Netscape ▫Facilitates disciplined approach.
 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.
Internet & World Wide Web How to Program, 5/e © by Pearson Education, Inc. All Rights Reserved.
This is our seminar JavaScript And DOM This is our seminar JavaScript And DOM.
Chapter 4 Java Script - Part1. 2 Outlines Introduction to Java Script Variables, Operators and Functions Conditional statements JavaScript Objects Forms.
JavaScript Events Java 4 Understanding Events Events add interactivity between the web page and the user You can think of an event as a trigger that.
JavaScript Events. Understanding Events Events add interactivity between the web page and the user Events add interactivity between the web page and the.
1 JavaScript/Jscript 2 Control Structures I. 2 Introduction Before programming a script have a –Thorough understanding of problem –Carefully planned approach.
INTERNET APPLICATIONS CPIT405 JavaScript Instructor: Rasha AlOmari
WEB SYSTEMS & TECHNOLOGY. Java Script  JavaScript created by Netscape  It is also client side programming  It can be use for client side checks.
JavaScript: Control Structures I Outline 1 Introduction 2 Algorithms 3 Pseudocode 4 Control Structures 5 if Selection Structure 6 if/else Selection Structure.
 2001 Prentice Hall, Inc. All rights reserved. Outline 1 JavaScript.
Chapter 14 - JavaScript/JScript: Control Structures I
JavaScript: Control Structures I
Chapter 6 JavaScript: Introduction to Scripting
Chapter 13 - JavaScript/JScript: Introduction to Scripting
Chapter 7 - JavaScript: Introduction to Scripting
Chapter 8 - JavaScript: Control Structures I
JavaScript: Introduction to Scripting
WEB PROGRAMMING JavaScript.
Chapter 7 - JavaScript: Introduction to Scripting
JavaScript: Introduction to Scripting
Chapter 7 - JavaScript: Introduction to Scripting
Chapter 7 - JavaScript: Introduction to Scripting
Chapter 8 - JavaScript: Control Structures I
Web Programming and Design
Chapter 7 - JavaScript: Introduction to Scripting
Presentation transcript:

1 Chapter 3 – JavaScript Outline Introduction Flowcharts Control Structures if Selection Structure if/else Selection Structure while Repetition Structure (Counter-Controlled Repetition) window objects Events

2 Introduction JavaScript was designed to add interactivity to HTML pages. It can mix with HTML. It is object based (have properties and methods). It is interpreted language (scripts execute without preliminary compilation). JavaScript is case sensitive (lower and upper are different). JavaScript code can be in,, or in external file with extension.js.

3 JavaScript: Introduction to Scripting Note : : tag indicates the browser that the text which follows is part of script. Type: is an attribute specifies the type of the file as well as the scripting language. We can write document: is an object allows a script programmer to specify text to display in HTML document. writeln: is an method that write a line of HTML markup in HTML document. parseInt : is an method using to convert string to integer( number ). JavaScript syntax: Script code here

4 document.writeln("Introduction to Scripting");

5 Flowcharts Flowcharting: mechanism allow the programmer to convert source code to chart to be more understanding and easy tracing. OperationChart Start and end Process Such as adding or multiply Enter or output (print) data Decision or condition

6 Control Structures A control structure specifies the way of execution statement, we have three types as follows: Sequence structure: statement in program execute on after the other. Selection structure: perform different action based on different condition (if statement). Repetition structure: execute the same block of code a specific number of times.

7 8.4 Control Structures Flowcharting JavaScript’s sequence structure.

8 if/else Selection Structure Flowcharting the single-selection if structure. grade >= 60 true false Print”Passed”

9 if/else Selection Structure grade >= 60 true print “ Failed ” false print “ Passed ” Flowcharting the double-selection if/else structure.

10 var grade; var gradeValue; grade=window.prompt("enter your grade"); gradeValue = parseInt( grade ); if(gradeValue >= 80) document.writeln("very good"); else document.writeln("good");

11 (Counter-Controlled Repetition) product <=10 true false Flowcharting the while repetition structure. Print product

12 (Counter-Controlled Repetition) A second Program in JavaScript var product; product=1; while(product <= 5) { document.writeln("product"+product) product=product+1; }

13 Window Object MethodDescription alert()Pops up an alert to viewer confirm()Displays a confirmation dialog box to the viewer find()Enable the viewer to lunch the find utility in the browser print()Prints the content of window open()Opens a new browser window close()Closes a browser window home()Sends the viewer to the home page prompt()Pops up a prompt dialog box asking the viewer to input information statusDisplays a text in a status bar of the window

14 Examples 1: window.confirm("welcome to my page");.

var name=window.prompt("Enter your name");

16 JavaScript Events EventEvent Trigger onClickViewer clicks an area ( such as a button or form input area) onLoadWeb page finishes loading onUnloadViewer leaves the current page onChangeViewer changes the contents of a form element onErrorAn error occurs in the loading of a page or image onKeyDownViewer presses down a key on the keyboard onKeyPressViewer presses a key on the keyboard and releases or holds the key down By using JavaScript, we have the ability to create dynamic web pages. Events are actions that can be detected by JavaScript.

17 JavaScript Events EventEvent Trigger onMouseDownViewer presses the mouse button onMouseUpViewer releases the mouse button onMouseMoveViewer moves the mouse( or moves the cursor) onMouseOverViewer moves the mouse over a link onMouseOutViewer moves the mouse away a link

18 Example 1. don’t click

Outline 19 welcome.html Program Output A First Program in JavaScript document.writeln( " Welcome to JavaScript Programming! " ); The document object’s writeln method writes a line of XHTML markup in the XHTML document. The script tag indicates to the browser that the text which follows is part of a script.

Outline 20 Average.html Class Average Program <!-- var total, // sum of grades gradeCounter, // number of grades entered gradeValue, // grade value average, // average of all grades grade; // grade typed by user // Initialization Phase total = 0; // clear total gradeCounter = 1; // prepare to loop // Processing Phase while ( gradeCounter <= 10 ) { // loop 10 times // prompt for input and read grade from user grade = window.prompt( "Enter integer grade:", "0" ); // convert grade from a string to an integer gradeValue = parseInt( grade ); // add gradeValue to total total = total + gradeValue;

Outline 21 Average.html Program Output // add 1 to gradeCounter gradeCounter = gradeCounter + 1; } // Termination Phase average = total / 10; // calculate the average // display average of exam grades document.writeln( " Class average is " + average + " " ); // --> Click Refresh (or Reload) to run the script again Increment the counter. Write the result to the XHTML document.