Download presentation
Presentation is loading. Please wait.
Published byAlan Tucker Modified over 8 years ago
1
Java Script Programming
2
Review: Event Handling Text Box Title: Button
3
JavaScript Adds programming to web pages Performing calculations –Totaling the price or computing sales tax Verifying data –Credit cards Adapting the display to user needs
4
Basic JavaScript Everything inside is a program We can use variables and expressions –Pay = payRate*hours We can write and reuse our own functions
5
What are the variable names? HTML Form Widgets Demo Title: US Citizen: Freshman Sophomore Junior Senior Type your address here. red yellow
6
What are the variable names? HTML Form Widgets Demo Title: US Citizen: Freshman Sophomore Junior Senior Type your address here. red yellow All the same name
7
Functions A function is a piece of computation that takes 1 or more arguments (data) and returns a value In Javascript, you can make functions yourself, and there are also predefined functions.
8
Creating your functions Tell the browser that you are going to write code. Use the tag
9
Functions To create a function function Name( parameterName,... ) {any JavaScript Code } To call a function –function Name(argument expression,... ) –Each argument is assigned to each parameter –The body { } of the function is executed.
10
An example function function pay(payRate,hours) { return payRate*hours; }
11
An example function function pay(payRate,hours) { return payRate*hours; } Variables
12
Function Demo function sayHello() { alert("Hello " + demoform.title.value) }
13
Putting Strings Together (concatenation) Use the “+” sign to put strings together. Demo
14
Functions with If and Else function evaluatePay() { if (demoform.totalPay.value < 100) { alert("You earn less than 100 dollars") } else { alert("You earn more than 100 dollars.") }
15
Functions with If and Else Demo
Similar presentations
© 2024 SlidePlayer.com Inc.
All rights reserved.