Abstraction and Functions Professor Robin Burke. 2 Outline Quiz JavaScript review Abstraction Function Definitions purpose syntax Functions return value.

Slides:



Advertisements
Similar presentations
1 CSC 533: Organization of Programming Languages Spring 2007 Java vs. JavaScript  JavaScript design goals  examples input/output, functions, numbers.
Advertisements

1 CSC 121 Computers and Scientific Thinking David Reed Creighton University Chapter 9 Abstraction and User-Defined Functions.
Chapter 20 Thinking Big: Functions. Copyright © 2006 Pearson Addison-Wesley. All rights reserved Anatomy of a Function Functions are packages for.
COMP 14 Introduction to Programming Miguel A. Otaduy May 25, 2004.
Math class methods & User defined methods Math class methods Math.sqrt(4.0) Math.random() java.lang is the library/package that provides Math class methods.
School of Computing Science CMT1000 © Ed Currie Middlesex University Lecture 10: 1 TEST!!
The UNIVERSITY of NORTH CAROLINA at CHAPEL HILL Adrian Ilie COMP 14 Introduction to Programming Adrian Ilie July 8, 2005.
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.
Introduction to JavaScript for Python Programmers
Event-driven Programming
Functions and Objects. First Midterm exam Date: October 8, 2008 Content: Two parts: On-paper:Multiple choices On-computer: Write codes Cover everything.
1 CSC 221: Introduction to Programming Fall 2012 Functions & Modules  standard modules: math, random  Python documentation, help  user-defined functions,
CMPS 211 JavaScript Topic 1 JavaScript Syntax. 2Outline Goals and Objectives Goals and Objectives Chapter Headlines Chapter Headlines Introduction Introduction.
Introduction to JavaScript Basharat Mahmood, Department of Computer Science, CIIT, Islamabad, Pakistan. 1.
 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.
Computers and Scientific Thinking David Reed, Creighton University Functions and Libraries 1.
Functions, Procedures, and Abstraction Dr. José M. Reyes Álamo.
1 CSC 121 Computers and Scientific Thinking David Reed Creighton University JavaScript and Dynamic Web Pages.
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.
CS346 Javascript -3 Module 3 JavaScript Variables.
CSC 121 Computers and Scientific Thinking David Reed Creighton University 1 Abstraction and User-Defined Functions.
THINKING BIG Abstraction and Functions chapter 6 Modified by Dr. Paul Mullins for CPSC 130, F05.
JavaScript III Functions and Abstraction. 2 JavaScript so far statements assignment function calls data types numeric string boolean expressions variables.
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.
Python Programming, 2/e1 Python Programming: An Introduction to Computer Science Chapter 6 Defining Functions.
Counter-Controlled Loops CSIS 1595: Fundamentals of Programming and Problem Solving 1.
Introduction to Programming JScript Six Scripting functions Discuss functions Password Example.
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.
Chapter 2: Variables, Functions, Objects, and Events JavaScript - Introductory.
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.
Loops Robin Burke IT 130. Outline Announcement: Homework #6 Conditionals (review) Iteration while loop while with counter for loops.
Making dynamic pages with javascript Lecture 1. Java script java versus javascript Javascript is a scripting language that will allow you to add real.
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.
Introduction to Functions CSIS 1595: Fundamentals of Programming and Problem Solving 1.
JavaScript Introduction and Background. 2 Web languages Three formal languages HTML JavaScript CSS Three different tasks Document description Client-side.
CSC 121 Computers and Scientific Thinking Fall Interactive Web Pages.
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 and Ajax (JavaScript Functions) Week 5 Web site:
Expressions and Data Types Professor Robin Burke.
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 and Dynamic Web Pages Lecture 7. 2 Static vs. Dynamic Pages  A Web page uses HTML tags to identify page content and formatting information.
1 CSC 121 Computers and Scientific Thinking David Reed Creighton University JavaScript and Dynamic Web Pages.
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.
ITM 3521 ITM 352 Functions. ITM 3522 Functions  A function is a named block of code (i.e. within {}'s) that performs a specific set of statements  It.
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.
© 2010 Robert K. Moniot1 Chapter 6 Introduction to JavaScript.
>> JavaScript: Location, Functions and Objects
Abstraction and Functions
4. Javascript Pemrograman Web I Program Studi Teknik Informatika
CHAPTER 4 CLIENT SIDE SCRIPTING PART 2 OF 3
Introduction to JavaScript for Python Programmers
T. Jumana Abu Shmais – AOU - Riyadh
Chapter 20: Programming Functions
Abstraction and User-Defined Functions
Chapter 9 Abstraction and User-Defined Functions
Chapter 7 Abstraction and User-Defined Functions
ITM 352 Functions.
Chapter 5 JavaScript Numbers and Expressions
Presentation transcript:

Abstraction and Functions Professor Robin Burke

2 Outline Quiz JavaScript review Abstraction Function Definitions purpose syntax Functions return value multiple parameters local variables Function libraries

3 Quiz 10 minutes

4 Quiz Answers

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

6 Example tempInFahr = prompt("Enter the 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.");

7 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

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

9 Function call syntax prompt ( "Enter a number", "0") return value is a string containing the user input function nameparameter #1 parameter #2 parameter list

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

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

13 Example CelsiusToFahr Old MacDonald 1 Old MacDonald 2

14 Scope With functions levels of interpretation Local what happens inside of a function Global what happens outside of the function

15 Scope example 1 animalcow soundundefined global "testmac.html" animal = prompt ( "Enter the...); sound = prompt ("What sound...);

16 Scope example 2 animalcow soundmoo global "testmac.html" animal = prompt ( "Enter the...); sound = prompt ("What sound...);

17 Scope example 3 animalcow soundmoo global "testmac.html" OldMacVerse (animal, sound); OldMacVerse ("duck", "quack");

18 Scope example 4 animalcow soundmoo global "testmac.html" OldMacVerse (animal, sound); OldMacVerse ("duck", "quack"); OldMacVerse animal cow soundmoo document.write (...)

19 Scope example 5 animalcow soundmoo global "testmac.html" OldMacVerse (animal, sound); OldMacVerse ("duck", "quack"); OldMacVerse animal cow soundmoo document.write (...) Old MacD..outputStringdocument.write??

20 Scope example 6 animalcow soundmoo global "testmac.html" OldMacVerse (animal, sound); OldMacVerse ("duck", "quack");

21 Scope example 7 animalcow soundmoo global "testmac.html" OldMacVerse (animal, sound); OldMacVerse ("duck", "quack"); OldMacVerse animal duck soundquack document.write (...)

22 Scope example 8 animalcow soundmoo global "testmac.html" OldMacVerse (animal, sound); OldMacVerse ("duck", "quack"); OldMacVerse animal duck soundquack document.write (...) Old MacD..outputStringdocument.write??

23 Scope example 9 animalcow soundmoo global "testmac.html" OldMacVerse (animal, sound); OldMacVerse ("duck", "quack");

24 Variable names Affect labels on boxes May affect what values are accessible

25 Renamed example 1 crittercow noiseundefined global "testmac.html" critter = prompt ( "Enter the...); noise = prompt ("What sound...);

26 Renamed example 2 crittercow noisemoo global "testmac.html" critter = prompt ( "Enter the...); noise = prompt ("What sound...);

27 Renamed example 3 crittercow noisemoo global "testmac.html" OldMacVerse (critter, noise); OldMacVerse ("duck", "quack");

28 Renamed example 4 crittercow noisemoo global "testmac.html" OldMacVerse (critter, noise); OldMacVerse ("duck", "quack"); OldMacVerse animal cow soundmoo document.write (...)

29 What if? we change the value of sound at the end of OldMacVerse sound = "snort"; we return a value from OldMacVerse typed nothing into the prompt canceled the prompt

30 Local variable example taxes.html

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

32 Example random.js pick4.html convert.js ctof2.html ftok.html

33 Debugging examples

34 Next class Algorithms Reading Ch. 8 Homework #4 due