CHAPTER 3 FUNCTIONS, METHODS & OBJECTS WHAT IS A FUNCTION?

Slides:



Advertisements
Similar presentations
JavaScript Objects - DOM CST 200 JavaScript. Objectives Introduce JavaScript objects Introduce Document Object Model Introduce window object Introduce.
Advertisements

Copyright © 2014 Dr. James D. Palmer; This work is licensed under a Creative Commons Attribution-ShareAlike 4.0 International License.
The Web Warrior Guide to Web Design Technologies
Computer Science 103 Chapter 3 Introduction to JavaScript.
Working with JavaScript. 2 Objectives Introducing JavaScript Inserting JavaScript into a Web Page File Writing Output to the Web Page Working with Variables.
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.
Programming Concepts MIT - AITI. Variables l A variable is a name associated with a piece of data l Variables allow you to store and manipulate data in.
Lesson15. JavaScript Objects Objects encapsulate data (properties) and behavior(methods); the properties and the methods of an object are tied together.
1 CS101 Introduction to Computing Lecture 29 Functions & Variable Scope (Web Development Lecture 10)
Chapter 6: Function. Scope of Variable A scope is a region of the program and broadly speaking there are three places, where variables can be declared:
Python quick start guide
Review and Practice for Final exam. Final exam Date: December 20, 3:15 – 5:15pm Format: Two parts: First part: multiple-choice questions (15 questions.
Test 2 Part a You have 20 minutes Don’t forget to put your name on the test Closed book No computers Do your own work.
Programming with JavaScript (Chapter 10). XP Various things Midterm grades: Friday Winter Career Fair – Thursday, April 28, 2011 (11 am to 3 pm). – MAC.
JavaScript Defined DOM (Document Object Model) General Syntax Body vs. Head Variables Math & Logic Selection Functions & Events Loops Animation Getting.
Generations of Programming Languages First generation  Machine Language Second Generation  Assembly Language Third Generation  Procedural language such.
The Document Object Model. Goals Understand how a JavaScript can communicate with the web page in which it “lives.” Understand how to use dot notation.
CSS Class 7 Add JavaScript to your page Add event handlers Validate a form Open a new window Hide and show elements Swap images Debug JavaScript.
The Web Wizard’s Guide To JavaScript Chapter 6 Working with Dates and Times.
Client Scripting1 Internet Systems Design. Client Scripting2 n “A scripting language is a programming language that is used to manipulate, customize,
Tutorial 2 Variables and Objects. Working with Variables and Objects Variables (or identifiers) –Values stored in computer memory locations –Value can.
ASP.NET Programming with C# and SQL Server First Edition Chapter 3 Using Functions, Methods, and Control Structures.
Chapter 4: Decision Making with Control Structures and Statements JavaScript - Introductory.
1 JavaScript in Context. Server-Side Programming.
XP Tutorial 10New Perspectives on Creating Web Pages with HTML, XHTML, and XML 1 Working with JavaScript Creating a Programmable Web Page for North Pole.
TUTORIAL 10: PROGRAMMING WITH JAVASCRIPT Session 2: What is JavaScript?
WDMD 170 – UW Stevens Point 1 WDMD 170 Internet Languages eLesson: Variables, Functions and Events (there is an audio component to this eLesson) © Dr.
CS-3432 Electronic Commerce Lecture – 13 Sikandar Shujah Toor
JS Basics 1 Lecture JavaScript - Basics. JS Basics 2 What is JavaScript JavaScript is a “simple”, interpreted, programming language with elementary object-
L OO P S While writing a program, there may be a situation when you need to perform some action over and over again. In such situation you would need.
CS346 Javascript -3 Module 3 JavaScript Variables.
1Computer Sciences Department Princess Nourah bint Abdulrahman University.
Chapter 3 Functions, Events, and Control Structures JavaScript, Third Edition.
JavaScript Syntax, how to use it in a HTML document
Chapter 2: Variables, Functions, Objects, and Events JavaScript - Introductory.
JavaScript, Fourth Edition
Julian on JavaScript: Functions Julian M Bucknall, CTO.
PHP. PHP User Defined Functions Besides the built-in PHP functions, we can create our own functions. A function is a block of statements that can be used.
Chapter 15 JavaScript: Part III The Web Warrior Guide to Web Design Technologies.
JavaScript Introduction. Slide 2 Lecture Overview JavaScript background The purpose of JavaScript A first JavaScript example Introduction to getElementById.
4. Javascript M. Udin Harun Al Rasyid, S.Kom, Ph.D Lab Jaringan Komputer (C-307) Desain.
JavaScript Defined DOM (Document Object Model) General Syntax Body vs. Head Variables Math & Logic Selection Functions & Events Loops Animation Getting.
Pertemuan 5 IT133 Pengembangan Web JavaScript. What is JavaScript? JavaScript was designed to add interactivity to HTML pages JavaScript is a scripting.
JavaScript. JavaScript Introduction JavaScript is the world's most popular programming language. It is the language for HTML and the web, for servers,
MTA EXAM HTML5 Application Development Fundamentals.
Introduction to JavaScript MIS 3502, Spring 2016 Jeremy Shafer Department of MIS Fox School of Business Temple University 2/2/2016.
Expressions and Data Types Professor Robin Burke.
4.1. Manage and maintain JavaScript Update the UI by using JavaScript. Understanding JavaScript and Coding Essentials.
JavaScript Tutorial. What is JavaScript JavaScript is the programming language of HTML and the Web Programming makes computers do what you want them to.
JavaScript Tutorial First lecture 19/2/2016. Javascript is a dynamic computer programming language. It is lightweight and most commonly used as a part.
 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,
The Web Wizard’s Guide To JavaScript Chapter 4 Image Swapping.
Midterm 2 Review. What does it mean to “declare a variable” in JavaScript? Write code to declare a variable with a name of your own choosing, in Javascript.
1 The Document Object Model. 2 Objectives You will be able to: Describe the structure of the W3C Document Object Model, or DOM. Use JavaScript to access.
Introduction to JavaScript MIS 3502, Fall 2016 Jeremy Shafer Department of MIS Fox School of Business Temple University 9/29/2016.
Programming Web Pages with JavaScript
Just enough to get going!
>> JavaScript: Location, Functions and Objects
Tutorial 10 Programming with JavaScript
CHAPTER 4 CLIENT SIDE SCRIPTING PART 3 OF 3
Web Design II Flat Rock Community Schools
Programming the Web using XHTML and JavaScript
4. Javascript Pemrograman Web I Program Studi Teknik Informatika
Introduction to Programming the WWW I
JavaScript Introduction
Chapter 20: Programming Functions
Tutorial 10: Programming with javascript
CHAPTER 3 FUNCTIONS, METHODS & OBJECTS
CHAPTER 2 BASIC JAVASCRIPT INSTRUCTIONS
[Robert W. Sebesta, “Programming the World Wide Web
Presentation transcript:

CHAPTER 3 FUNCTIONS, METHODS & OBJECTS

WHAT IS A FUNCTION?

Functions let you group a series of statements together to perform a specific task.

Functions are reusable and save you from writing out the same code over and over.

DECLARING A FUNCTION

function

function sayHello()

function sayHello() { document.write(‘Hello’); }

KEYWORD

function sayHello() { document.write(‘Hello’); } FUNCTION NAME

function sayHello() { document.write(‘Hello’); } CODE BLOCK (IN CURLY BRACES)

CALLING A FUNCTION

sayHello();

FUNCTION NAME

DECLARING A FUNCTION THAT NEEDS INFORMATION

function

function getArea()

function getArea(width, height)

function getArea(width, height) { return width * height; }

PARAMETER

function getArea(width, height) { return width * height; } THE PARAMETERS ARE USED LIKE VARIABLES WITHIN THE FUNCTION

CALLING A FUNCTION THAT NEEDS INFORMATION

getArea(3, 5);

ARGUMENTS

OBJECTS

Objects group together variables and functions to create a model.

In an object, variables and functions take on new names. They become properties and methods.

Each property or method consists of a name (also known as a key) and its corresponding value.

var hotel = { name: ‘Quay’, rooms: 40, booked: 25, gym: true, roomTypes: [‘twin’, ‘double’, ‘suite’], checkAvailability: function() { return this.rooms - this.booked; } };

var hotel = { name: ‘Quay’, rooms: 40, booked: 25, gym: true, roomTypes: [‘twin’, ‘double’, ‘suite’], checkAvailability: function() { return this.rooms - this.booked; } };

var hotel = { name: ‘Quay’, rooms: 40, booked: 25, gym: true, roomTypes: [‘twin’, ‘double’, ‘suite’], checkAvailability: function() { return this.rooms - this.booked; } }; NAMES (KEYS)

var hotel = { name: ‘Quay’, rooms: 40, booked: 25, gym: true, roomTypes: [‘twin’, ‘double’, ‘suite’], checkAvailability: function() { return this.rooms - this.booked; } }; VALUES

var hotel = { name: ‘Quay’, rooms: 40, booked: 25, gym: true, roomTypes: [‘twin’, ‘double’, ‘suite’], checkAvailability: function() { return this.rooms - this.booked; } }; PROPERTIES

var hotel = { name: ‘Quay’, rooms: 40, booked: 25, gym: true, roomTypes: [‘twin’, ‘double’, ‘suite’], checkAvailability: function() { return this.rooms - this.booked; } }; METHOD

ACCESSING OBJECTS

var hotelName = hotel.name;

OBJECT

var hotelName = hotel.name; PROPERTY

var hotelName = hotel[‘name’];

OBJECT

var hotelName = hotel[‘name’]; PROPERTY

UPDATING OBJECTS

hotel.name = ‘Park’;

OBJECT

hotel.name = ‘Park’; PROPERTY

hotel.name = ‘Park’; NEW VALUE

hotel[‘name’] = ‘Park’;

OBJECT

hotel[‘name’] = ‘Park’; PROPERTY

hotel[‘name’] = ‘Park’; NEW VALUE

BUILT-IN OBJECTS

1

Browser Object Model THE WEB BROWSER 1

BROWSER OBJECT MODEL PROPERTIES INCLUDE: window.innerHeight window.innerWidth window.screenX window.screenY METHODS INCLUDE: window.print()

2 1 Browser Object Model THE WEB BROWSER

12 Document Object Model THE PAGE LOADED IN THE WEB BROWSER (OR TAB) Browser Object Model THE WEB BROWSER

DOCUMENT OBJECT MODEL PROPERTIES INCLUDE: document.title document.lastModified METHODS INCLUDE: document.write() document.getElementById()

3 12 Browser Object Model THE WEB BROWSER Document Object Model THE PAGE LOADED IN THE WEB BROWSER (OR TAB)

3 Global JavaScript Objects GENERAL PURPOSE OBJECTS JAVASCRIPT NEEDS TO WORK 12 Browser Object Model THE WEB BROWSER Document Object Model THE PAGE LOADED IN THE WEB BROWSER (OR TAB)

GLOBAL JAVASCRIPT OBJECTS PROPERTIES INCLUDE: saying.length METHODS INCLUDE: saying.toUpperCase() saying.toLowerCase() saying.charAt(3)