JavaScript III Functions and Abstraction. 2 JavaScript so far statements assignment function calls data types numeric string boolean expressions variables.

Slides:



Advertisements
Similar presentations
Etter/Ingber Engineering Problem Solving with C Fundamental Concepts Chapter 4 Modular Programming with Functions.
Advertisements

1 What is JavaScript? JavaScript was designed to add interactivity to HTML pages JavaScript is a scripting language A scripting language is a lightweight.
CSE 251 Dr. Charles B. Owen Programming in C1 Functions.
1 CSC 121 Computers and Scientific Thinking David Reed Creighton University Chapter 9 Abstraction and User-Defined Functions.
1 Programmer-Defined Functions Functions allow program modularization Variables declared in function are local variables Only known inside function in.
The Web Warrior Guide to Web Design Technologies
C Lecture Notes 1 Program Control (Cont...). C Lecture Notes 2 4.8The do / while Repetition Structure The do / while repetition structure –Similar to.
Chapter 6: User-Defined Functions I
FunctionsFunctions Systems Programming. Systems Programming: Functions 2 Functions   Simple Function Example   Function Prototype and Declaration.
Introduction to Computers and Programming Lecture 13: User defined methods Instructor: Evan Korth New York University.
Javascript II Expressions and Data Types. 2 JavaScript Review programs executed by the web browser programs embedded in a web page using the script element.
Outline IS400: Development of Business Applications on the Internet Fall 2004 Instructor: Dr. Boris Jukic JavaScript: Functions Part I.
Lesson15. JavaScript Objects Objects encapsulate data (properties) and behavior(methods); the properties and the methods of an object are tied together.
Database-Driven Web Sites, Second Edition1 Chapter 3 INTRODUCTION TO CLIENT-SIDE SCRIPTS.
Functions and Objects. First Midterm exam Date: 10/10/2006 (Tuesday) Content: Multiple choices Determine results of the code Write codes Covert everything.
Functions and Objects. First Midterm exam Date: October 8, 2008 Content: Two parts: On-paper:Multiple choices On-computer: Write codes Cover everything.
© Copyright 1992–2004 by Deitel & Associates, Inc. and Pearson Education Inc. All Rights Reserved. C How To Program - 4th edition Deitels Class 05 University.
 2008 Pearson Education, Inc. All rights reserved JavaScript: Functions.
 2003 Prentice Hall, Inc. All rights reserved. CHAPTER 3 JavaScript 1.
Dynamic Web Pages & JavaScript. Dynamic Web Pages Dynamic = Change Dynamic Web Pages are web pages that change. More than just moving graphics around.
1 Functions Lecfture Abstraction abstraction is the process of ignoring minutiae and focusing on the big picture in modern life, we are constantly.
Functions. Type of Subprograms Fortran 90/95 allows for two types of subprograms: –Functions, and –Subroutines. In general, there are two forms of subprograms:
Functions, Procedures, and Abstraction Dr. José M. Reyes Álamo.
CPS120: Introduction to Computer Science Functions.
CPS120: Introduction to Computer Science Lecture 14 Functions.
Java Script User Defined Functions. Java Script  You can define your own JavaScript functions. Such functions are called user- defined, as opposed to.
David Stotts Computer Science Department UNC Chapel Hill.
CSC 121 Computers and Scientific Thinking David Reed Creighton University 1 Abstraction and User-Defined Functions.
Created by, Author Name, School Name—State FLUENCY WITH INFORMATION TECNOLOGY Skills, Concepts, and Capabilities.
Chapter 3 Functions, Events, and Control Structures JavaScript, Third Edition.
Chapter 4 - Visual Basic Schneider1 Chapter 4 General Procedures.
JavaScript Scripting language What is Scripting ? A scripting language, script language, or extension language is a programming language.
1 A Balanced Introduction to Computer Science David Reed, Creighton University ©2005 Pearson Prentice Hall ISBN X Chapter 4 JavaScript and.
Covenant College November 27, Laura Broussard, Ph.D. Professor COS 131: Computing for Engineers Chapter 5: Functions.
© Copyright 1992–2004 by Deitel & Associates, Inc. and Pearson Education Inc. All Rights Reserved. Chapter 5 - Functions Outline 5.1Introduction 5.2Program.
© Copyright 1992–2004 by Deitel & Associates, Inc. and Pearson Education Inc. All Rights Reserved. Functions Outline 5.1Introduction 5.2Program Modules.
KIC/Computer Programming & Problem Solving 1.  Introduction  Program Modules in C  Math Library Functions  Functions  Function Definitions  Function.
1 A Balanced Introduction to Computer Science, 2/E David Reed, Creighton University ©2008 Pearson Prentice Hall ISBN Chapter 5 JavaScript.
JavaScript, Fourth Edition
Variables and Assignment CSIS 1595: Fundamentals of Programming and Problem Solving 1.
1 Functions, Part 1 of 2 Topics Using Predefined Functions Programmer-Defined Functions Using Input Parameters Function Header Comments.
4. Javascript M. Udin Harun Al Rasyid, S.Kom, Ph.D Lab Jaringan Komputer (C-307) Desain.
Javascript JavaScript is what is called a client-side scripting language:  a programming language that runs inside an Internet browser (a browser is also.
Chapter 2 Murach's JavaScript and jQuery, C2© 2012, Mike Murach & Associates, Inc.Slide 1.
Functions Function is a standalone block of statements that performs some tasks and returns a value. Functions must be declared before they can be used.
Introduction to Functions CSIS 1595: Fundamentals of Programming and Problem Solving 1.
PHP Reusing Code and Writing Functions 1. Function = a self-contained module of code that: Declares a calling interface – prototype! Performs some task.
JavaScript Introduction and Background. 2 Web languages Three formal languages HTML JavaScript CSS Three different tasks Document description Client-side.
5 th and 4 th ed: Chapters 9, 10, 11 SY306 Web and Databases for Cyber Operations SlideSet #7: JavaScript Functions and Arrays.
JavaScript and Ajax (JavaScript Functions) Week 5 Web site:
Abstraction and Functions Professor Robin Burke. 2 Outline Quiz JavaScript review Abstraction Function Definitions purpose syntax Functions return value.
Expressions and Data Types Professor Robin Burke.
Dale Roberts CSCI N305 Functions Declarations Department of Computer and Information Science, School of Science, IUPUI.
FUNCTIONS (C) KHAERONI, M.SI. OBJECTIVE After this topic, students will be able to understand basic concept of user defined function in C++ to declare.
1 Agenda  Unit 7: Introduction to Programming Using JavaScript T. Jumana Abu Shmais – AOU - Riyadh.
 The real power of PHP comes from its functions; it has more than 1000 built-in functions.  PHP User Defined Functions  Besides the built-in PHP functions,
Functions. What is a Function?  We have already used a few functions. Can you give some examples?  Some functions take a comma-separated list of arguments.
Abstraction and Functions
4. Javascript Pemrograman Web I Program Studi Teknik Informatika
User-Defined Functions
Functions Declarations CSCI 230
T. Jumana Abu Shmais – AOU - Riyadh
JavaScript What is JavaScript? What can JavaScript do?
JavaScript What is JavaScript? What can JavaScript do?
G. Pullaiah College of Engineering and Technology
Chapter 20: Programming Functions
Abstraction and User-Defined Functions
Tutorial 10: Programming with javascript
Chapter 5 JavaScript Numbers and Expressions
Presentation transcript:

JavaScript III Functions and Abstraction

2 JavaScript so far statements assignment function calls data types numeric string boolean expressions variables operators function calls

Review by Example From W3Schools JavaScript Examples 3

4 Review by Example tempInFahr = prompt("Enter temperature (in Fahrenheit):", "32"); tempInFahr = parseFloat(tempInFahr); tempInCelsius = (5/9) * (tempInFahr - 32); document.write("You entered " + tempInFahr + " degrees Fahrenheit. "); document.write("That's equivalent to " + tempInCelsius + " degrees Celsius.");

5 Abstraction JavaScript has built-in functions document.write Math.sqrt Benefit of abstraction we don't have to write these we don't have to know how they work Fundamental idea in computer science

6 User-defined functions Our own abstractions FahrToCelsius Benefits code once, use often fix/enhance in one place add structure to large programs groups and names chunks of computation

7 Function Calls When a we use a function in the body of a program, it is a “function call” Use the name of the function along with values for its parameters. Function call acts as a black box & returns a value. The returned value can be stored in some variable. Example tempInFahr = prompt("Enter temp. (in Fahrenheit):", "32"); tempInFahr = parseFloat(tempInFahr);

8 Function Call Syntax prompt ( "Enter a number", "0") return value, in this case is a string containing the user input function nameparameter #1 parameter #2 parameter list

9 Function definition example function FahrToCelsius (tempInFahr) { return (5/9) * (tempInFahr – 32); } declaration start function nameparameter names function body start of body end of body

10 Function Definitions Format of a function definition function function-name ( parameter-list ) { declarations and statements } Function name any valid identifier Parameter list names of variables that will receive arguments Must have same number as function call May be empty Declarations and statements Function body (“block” of code)

11 return statement Math.sqrt returns a value document.write does not If a return statement exists function will return a value what value? If not no value

12 return statement Returning control return statement Can return either nothing, or a value return expression ; No return statement same as return; Not returning a value when expected is an error Example Math.sqrt returns a value document.write does not

13 Example: User-Defined Functions convert.html

14 Documentation Functions are self-contained meant to be used elsewhere eventually by others Documentation very important function FahrToCelsius (tempInFahr) // Assumes: tempInFahr is a temperature in Fahrenheit // Returns: the equivalent temperature in Celsius { return (5/9) * (tempInFahr – 32); }

15 Scope of variables With functions different levels of interpretation Local what happens inside of a function Global what happens outside of the function

16 Local Variables All variables declared in function are called local Do not exist outside current function Parameters Also local variables Promotes reusability Keep short Name clearly

17 Local/Global Variable Example taxes.html

18 Libraries We can define a group of functions usually related Separate file.js extension Load using script tag Call functions from page

19 Examples of Using Libraries convert.js convert2.html In Class Practice: ftok.html