Presentation is loading. Please wait.

Presentation is loading. Please wait.

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

Similar presentations


Presentation on theme: "CHAPTER 3 FUNCTIONS, METHODS & OBJECTS WHAT IS A FUNCTION?"— Presentation transcript:

1

2 CHAPTER 3 FUNCTIONS, METHODS & OBJECTS

3 WHAT IS A FUNCTION?

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

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

6 DECLARING A FUNCTION

7 function

8 function sayHello()

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

10 KEYWORD

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

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

13 CALLING A FUNCTION

14 sayHello();

15 FUNCTION NAME

16 DECLARING A FUNCTION THAT NEEDS INFORMATION

17 function

18 function getArea()

19 function getArea(width, height)

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

21 PARAMETER

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

23 CALLING A FUNCTION THAT NEEDS INFORMATION

24 getArea(3, 5);

25 ARGUMENTS

26 OBJECTS

27 Objects group together variables and functions to create a model.

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

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

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

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

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

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

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

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

36 ACCESSING OBJECTS

37 var hotelName = hotel.name;

38 OBJECT

39 var hotelName = hotel.name; PROPERTY

40 var hotelName = hotel[‘name’];

41 OBJECT

42 var hotelName = hotel[‘name’]; PROPERTY

43 UPDATING OBJECTS

44 hotel.name = ‘Park’;

45 OBJECT

46 hotel.name = ‘Park’; PROPERTY

47 hotel.name = ‘Park’; NEW VALUE

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

49 OBJECT

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

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

52 BUILT-IN OBJECTS

53 1

54 Browser Object Model THE WEB BROWSER 1

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

56 2 1 Browser Object Model THE WEB BROWSER

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

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

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

60 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)

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

62


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

Similar presentations


Ads by Google