CS142 Project #6: Javascript and the DOM

Problem 1: Javascript Calendar (25 points)

Create a new directory project6 that will contain the solution for this project. Within that directory, create a file Calendar.js that implements a Javascript class named Calendar that can be used as in the following example:

var calendar = new Calendar("div1");
calendar.render(new Date("July 4, 1776"));

The constructor takes a single argument consisting of the id attribute for a div, and the render method takes one argument consisting of a Date object that selects a particular month (the object can refer to any time within the month). When render is invoked it replaces the contents of the calendar's div with HTML that displays a small one-month calendar such as those you might see in an airline reservation Web site:

The calendar does not need to do anything if the user clicks on a particular date; all it needs to do is display one month and allow the month to be changed by clicking on the controls.

Once you have created the Javascript class, create an HTML file calendar.html that uses the Javascript class to display two different calendar divs. One of the calendars should initially display the current month and the other should display the month of January, 2009. It should be possible to change the month of each calendar independently, using the controls on that calendar.

Problem 2: Traversing a Table (15 points)

Create a file TableScan.js that implements a Javascript class named TableScan with a static method sumColumn. This method takes two arguments consisting of the id attribute for a <table> and a string identifying a column in the table. The method must search the topmost row of the table to find an entry matching the string argument. This selects a particular column in the table (if there is no matching column, the method returns 0). Then the method must find all of the values in that column (excluding the header value), treat them as numbers, and return the sum of all of those values. If a column contains any non-numeric values, you should treat them as if they were 0. Also, beware that browsers insert a <tbody> element around all of the <tr> elements in a table, if the table doesn't already contain a <tbody>.

Once you have created the Javascript class, open this zip file and copy the files tableScan.html and tableScan.css into the project6 directory. These files represent an HTML page containing three sample tables. Modify tableScan.html to add the following elements:

You may add additional styles to tableScan.css if needed.

Additional Requirements, Hints, etc.

Style Points (10 points)

The most important criterion for these points is whether your Calendar implementation is reusable. In addition, your Javascript must be clean (appropriate use of classes, no global variables other than constructor functions, etc.).

Deliverables

Use the standard class submission mechanism to submit the entire project6 directory.