Presentation is loading. Please wait.

Presentation is loading. Please wait.

Functions and Parameters. Structured Programming.

Similar presentations


Presentation on theme: "Functions and Parameters. Structured Programming."— Presentation transcript:

1 Functions and Parameters

2 Structured Programming

3 Modular, Structured Programs Program: –Sequences, conditionals, and loops. –Cohesive blocks of code. –Request that blocks of code do work.  Transition to objects.

4 Task Generate payroll for employees.

5 Steps Retrieve employee information. Retrieve payroll data for employee. Calculate gross pay. Calculate federal income tax. Calculate FICA tax. Calculate state tax. Calculate net pay. Transfer net pay to employee account. Transfer taxes to tax liability accounts. Generate pay statement.

6 Structure Get Employee Data Retrieve employee information Retrieve payroll data for employee Calculate gross pay Calculate federal income tax Calculate FICA tax Calculate state tax Calculate net pay Transfer net pay to employee account Transfer taxes to tax liability accounts Compute Net Pay Deposit Funds Prepare Pay Statement Employees Remaining? Generate pay statement

7 Modules Get Employee Data Retrieve employee information Retrieve payroll data for employee Calculate gross pay Calculate federal income tax Calculate FICA tax Calculate state tax Calculate net pay Transfer net pay to employee account Transfer taxes to tax liability accounts Generate pay statement Compute Net Pay Deposit Funds Prepare Pay Statement Employees Remaining?

8 Benefits Easier programming. Easier, better testing – modules. Easier maintenance. Reusable modules.

9 Basic Functions

10 Function Module of code. Each function should: –Perform a well-defined task. –Be self contained. –Receive the minimum data to perform task. Return value is optional.

11 function popupMessage() { alert('Hello\nHow are you today?') } popupMessage() alert('Hello’)

12 Function Declaration function popupMessage() { alert('Hello\nHow are you today?') } declarationnameparameter list start of function code end of function code

13 Parameters

14 Function with Parameter function popupMessage(message) { alert(message) } parameter use of parameter in function popupMessage('Oh no!') show = 'JavaScript is fun!' popupMessage('show') popupMessage(show) function call using a parameter Oh no! JavaScript is fun!

15 Multiple Parameters function popupMessage(line1, line2) { alert(line1 + '\n' + line2) } popupMessage('Oh no!', 'Mr. Bill') show1 = 'JavaScript is fun!' show2 = 'HTML is easy' popupMessage(show1, show2) parameters function call with multiple parameters

16 Image Rollovers

17 Implementation Overview Precaching. Multiple images. OnMouseOver event. OnMouseOut event.

18 alert(document.images[0].src) alert(document.images.pic1.src) alert(document.getElementById('pic1').src) index id by id using method images collection Referencing Elements

19 getElementById document.getElementById(id).target target’s id property or method based on target’s type (e.g., img) Recommended for accessing HTML elements in JavaScript

20 Debugging

21 Techniques Browser options: –IE: Enable script error notifications. –Mozilla: Use JavaScript console. Debug messages: –Display “current position” alerts in code. –Display intermediate computations.

22 var screenHeight = 0 var screenWidth = 0 var usableHeight = 0 var usableWidth = 0 var verticalWaste = 0 var horizontalWaste = 0 screenHeight = screen.availHeight screenWidth = screen.availWidth usableHeight = document.body.clientHeight usableWidth = documnet.body.clientWidth verticalWaste = screenHeight - usableHeight horizontalWaste = screenWidth – usableWidth alert('Vertical Waste: ' + verticalWaste + '\n' + 'Horizontal Waste: ' + horizontalWaste) alert(‘ok so far’) alert(screenHeight)

23


Download ppt "Functions and Parameters. Structured Programming."

Similar presentations


Ads by Google