Javascript (I/O, Control, Arrays, Objects, Regex, Functions)




CS174

Chris Pollett

April 6, 2016

Outline

typeof, Assignments, and the Date Object

I/O

Control Statements

Objects

Arrays

More Arrays

Let's Build Something

Make an HTML page with a form on it with text fields labeled First Name, Last Name, and Age, and with a button Save. Clicking the button Save should store into a Javascript object person with fields fname, lname, and age. Beneath the form on the HTML page have a link which when clicked causes an alert to be displayed with the contents of the person object neatly drawn.

Post your answers to the April 6 Let's Build something Thread.

Functions

Function Example

function swap(i, j, a)
{
	var tmp=a[i]; /* explicitly defined variables 
                         have scope within the function
                         if I had declared the variable 
                         implicitly it would have global scope */
	a[i] = a[j]; a[j] = tmp;
}

Constructors

Methods

More on the Prototype Property