function < name > ( < parameter list > ) { < statements >

Similar documents
Functions. INFO/CSE 100, Spring 2006 Fluency in Information Technology.

Anatomy of a Function. Pick a Name. Parameters. Definition. Chapter 20: Thinking Big: Programming Functions

Non-English Web Pages In Dreamweaver MX

JAVASCRIPT - CREATING A TOC

Programming Basics. INFO/CSE 100, Spring 2006 Fluency in Information Technology.

CMPT 100 : INTRODUCTION TO

Unit Notes. ICAWEB411A Produce basic client-side script for dynamic web pages Topic 1 Introduction to JavaScript

Session 3: JavaScript - Structured Programming

Programming Basics. INFO/CSE 100, Spring 2005 Fluency in Information Technology.

What is XHTML? XHTML is the language used to create and organize a web page:

Implementing a chat button on TECHNICAL PAPER

Here are a few easy steps to create a simple timeline. Open up your favorite text or HTML editor and start creating an HTML file.

CSCU9B2 Practical 1: Introduction to HTML 5

c122mar413.notebook March 06, 2013

CSE 115. Introduction to Computer Science I

Documents and computation. Introduction to JavaScript. JavaScript vs. Java Applet. Myths. JavaScript. Standard

Chapter 3 - Simple JavaScript - Programming Basics. Lesson 1 - JavaScript: What is it and what does it look like?

Lab 4 CSS CISC1600, Spring 2012

CSC Web Programming. Introduction to JavaScript

Basic CSS Tips and Tricks

Manju Muralidharan Priya. CS4PM Web Aesthetics and Development WEEK 11

introduction to XHTML

Why HTML5? Why not XHTML2? Learning from history how to drive the future of the Web

2.) You need personal webspace. This is usually provided by your Internet service provider. Check with your ISP on how to set up the webspace.

GIMP WEB 2.0 MENUS. Before we begin this tutorial let s visually compare a standard navigation bar and a web 2.0 navigation bar.

What is CSS? NAME: INSERT OPENING GRAPHIC HERE:

The course also includes an overview of some of the most popular frameworks that you will most likely encounter in your real work environments.

Recall: Document Object Model (DOM)

Working with JavaScript

Scripting. Web Architecture and Information Management [./] Spring 2009 INFO (CCN 42509) Contents

استاد: امیر عسگری چناقلو ترم دوم درس طراحی صفحات وب

Web Programming and Design. MPT Junior Cycle Tutor: Tamara Demonstrators: Aaron, Marion, Hugh

Introduction to HTML5

Introduction to HTML5

JavaScript CS 4640 Programming Languages for Web Applications

For live Java EE training, please see training courses at

1 of 5 09/16/01 10:11 PM

Bookmarks to the headings on this page:

Build Site Create your site

HTML HTML. Chris Seddon CRS Enterprises Ltd 1

HTML Overview. With an emphasis on XHTML

LA TROBE UNIVERSITY SEMESTER ONE EXAMINATION PERIOD CAMPUS AW BE BU MI SH ALLOWABLE MATERIALS

Markup Language. Made up of elements Elements create a document tree

So, if you receive data from a server, in JSON format, you can use it like any other JavaScript object.

"a computer programming language commonly used to create interactive effects within web browsers." If actors and lines are the content/html......

Web Programming and Design. MPT Junior Cycle Tutor: Tamara Demonstrators: Aaron, Marion, Hugh

INTRODUCTION TO JAVASCRIPT

Web Programming and Design. MPT Senior Cycle Tutor: Tamara Week 1

Session 5. Web Page Generation. Reading & Reference

This class is a formatter that takes Pod and renders it as XHTML validating HTML.

CNIT 129S: Securing Web Applications. Ch 12: Attacking Users: Cross-Site Scripting (XSS) Part 2

A340 Laboratory Session #5

COMP519 Practical 5 JavaScript (1)

Web Publishing Basics I

Graphing Data from MYSQL By Javier Montiel Urbina

Learning vrealize Orchestrator in action V M U G L A B

LAST WEEK ON IO LAB. Install Firebug and Greasemonkey. Complete the online skills assessment. Join the mailing list.

SEEM4570 System Design and Implementation. Lecture 3 Events

Practice Test 3. 2) The onload event handler is used, most often, in association with which tag? a) a b) p c) body d) form

Modify cmp.htm, contactme.htm and create scheduleme.htm

Tutorial on text transformation with pure::variants

COMS 469: Interactive Media II

Document Object Model (DOM)

Client Side JavaScript and AJAX

SEEM4570 System Design and Implementation. Lecture 3 Cordova and jquery

ATSC Week 2 Web Authoring

jmaki Overview Sang Shin Java Technology Architect Sun Microsystems, Inc.

A designers guide to creating & editing templates in EzPz

Tutorial 2 - HTML basics

Setup and Getting Startedt Customized Java EE Training:

Beginning HTML. The Nuts and Bolts of building Web pages.

HTML. HTML is now very well standardized, but sites are still not getting it right. HTML tags adaptation

Creating a New Project with Struts 2

First, create a web page with a submit button on it (remember from creating forms in html?):

Vebra Search Integration Guide

Semantic Web Lecture Part 1. Prof. Do van Thanh

Rolling Your Own Online Usability Study

Variables and Typing

Create a cool image gallery using CSS visibility and positioning property

MPT Web Design. Week 1: Introduction to HTML and Web Design

3Lesson 3: Functions, Methods and Events in JavaScript Objectives

Let s make a web game! credit: Photon Storm

PRODUCT DOCUMENTATION. Installing and Implementing Enterprise Contact Center Chat RELEASE 5.1

Applications & Application-Layer Protocols: The Web & HTTP

Tip: Install IIS web server on Windows 2008 R2

Chapter 10: Understanding the Standards

NOTE: There are an awful lot of synonyms for "function" "routine, map [ ], procedure, [ ], subroutine, [ ], subprogram, [ ], function"

PHP. Interactive Web Systems

In the early days of the Web, designers just had the original 91 HTML tags to work with.

CISC 1600 Lecture 2.4 Introduction to JavaScript

Skyway Builder 6.3 Spring Web Flow Tutorial

How browsers talk to servers. What does this do?

Document for Consuming Web-Service In.NET & JAVA

COMP284 Practical 6 JavaScript (1)

Using htmlarea & a Database to Maintain Content on a Website

Exercise 1: Basic HTML and JavaScript

Walking the DOM Tree. Lecture Outline. An example XHTML page. CSE 190 M (Web Programming), Spring 2008 University of Washington

Quick.JS Documentation

Web Scripting using PHP

Header. Report Section. Footer

Transcription:

Readings and References Functions INFO/CSE 100, Autumn 2004 Fluency in Information Technology http://www.cs.washington.edu/100 Reading» Fluency with Information Technology Chapter 20, Abstraction and Functions Other References» W3Schools JavaScript tutorial http://www.w3schools.com/js/default.asp» W3Schools JavaScript HTML DOM Objects http://www.w3schools.com/js/js_obj_htmldom.asp» Mozilla Browser http://www.mozilla.org/ 27-Oct-2004 cse100-12-functions 2004 University of Washington 1 27-Oct-2004 cse100-12-functions 2004 University of Washington 2 Functions A function is a way to bundle a set of instructions and give them a name so that you can reuse them easily Functions have a specific layout» <name> the function name is an identifier» <parameter list> list of input variables for the function» <statements> the statements do the work function <name> ( <parameter list> ) { <statements> Example Function function <name> ( <parameter list> ) { <statements> Write a simple function to compute the Body Mass Index when the inputs are in English units (ie, US units) var heightft = heightin / 12; // convert to feet 27-Oct-2004 cse100-12-functions 2004 University of Washington 3 27-Oct-2004 cse100-12-functions 2004 University of Washington 4

Develop the function First, make sure you understand what you want the function to do and how it will accomplish the task. function name(parameter list) { statements Pick a name for the function Function names are identifiers» start with a letter» should have a fairly obvious meaning function bmie(parameter list) { statements 27-Oct-2004 cse100-12-functions 2004 University of Washington 5 27-Oct-2004 cse100-12-functions 2004 University of Washington 6 Pick the parameters Parameter names are also identifiers» these are the variable names that your function will use when it is performing its calculations» should have a fairly obvious meaning statements Write the function body The function body includes whichever statements are required to implement the desired capability. var heightft = heightin / 12; // convert to feet 27-Oct-2004 cse100-12-functions 2004 University of Washington 7 27-Oct-2004 cse100-12-functions 2004 University of Washington 8

A Simple Testing Template Try the function and see how it works <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/tr/html4/loose.dtd"> <html> <head> <title>body Mass Index</title> // Figure Body Mass Index in English units function bmie( weightlbs, heightin ) { var heightft = heightin / 12; // Change to feet </head> <body> <p>this page provides a simple body mass index calculator. Normal weight corresponds to a BMI of 18.5-24.9</p> document.writeln("<br>bmie(100,72): "+bmie(100,72)); document.writeln("<br>bmie(150,72): "+bmie(150,72)); document.writeln("<br>bmie(175,72): "+bmie(175,72)); document.writeln("<br>bmie(200,72): "+bmie(200,72)); </body> </html> The new function Test statements 27-Oct-2004 cse100-12-functions 2004 University of Washington 9 27-Oct-2004 cse100-12-functions 2004 University of Washington 10 Fancy Function Features <head> <title>body Mass Index</title> var heightft = heightin / 12; // convert to feet </head> <script> in <head> location, comments, keywords, formal parameters, curly brackets, parentheses, operators, expressions, assignment statement, return statement, semi-colon 27-Oct-2004 cse100-12-functions 2004 University of Washington 11 Using Fancy Functions <body> <p>this page provides a simple body mass index calculator. Normal weight corresponds to a BMI of 18.5-24.9</p> document.writeln("<br>bmie(100,72): "+bmie(100,72)); document.writeln("<br>bmie(150,72): "+bmie(150,72)); document.writeln("<br>bmie(175,72): "+bmie(175,72)); document.writeln("<br>bmie(200,72): "+bmie(200,72)); </body> <script> in <body> location, document, writeln function call, strings, string concatenation, bmie function call, arguments (aka actual parameters) 27-Oct-2004 cse100-12-functions 2004 University of Washington 12

Comments on Debugging Use the W3Schools TryIt Editor Debugging JavaScript can be hard» The browsers all implement things a little differently, particularly old browsers upgrade if you are using something old! 27-Oct-2004 cse100-12-functions 2004 University of Washington 13 27-Oct-2004 cse100-12-functions 2004 University of Washington 14 Display results using alert(...) Use an editor that helps you Use the alert("this is a message") function The TextPad editor helps you by doing syntax highlighting. 27-Oct-2004 cse100-12-functions 2004 University of Washington 15 27-Oct-2004 cse100-12-functions 2004 University of Washington 16

Display results using writeln(...) Use a browser that helps you <body> document.writeln("somevariable: "+somevariable); </body> All browsers try to be forgiving of errors, which means that they generally don't produce a lot of error messages» use a browser that helps you debug like Mozilla 27-Oct-2004 cse100-12-functions 2004 University of Washington 17 27-Oct-2004 cse100-12-functions 2004 University of Washington 18 enable Mozilla JavaScript Console The Mozilla JavaScript console helps you by showing good error messages. 27-Oct-2004 cse100-12-functions 2004 University of Washington 19

By the way... Why don't these pages have a <META> tag with the charset attribute? <META HTTP-EQUIV="Content-Type" CONTENT="text/html; charset=iso-8859-1"> Because there's another way to fix the encoding issue. 1. Create a file named.htaccess in your public_html directory on dante. 2. Put the following text in that file using pico: AddType 'text/html; charset=iso-8859-1' html 27-Oct-2004 cse100-12-functions 2004 University of Washington 21