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.
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:
id
of a table and
the string identifying a column within that table.<a>
element that the user
can click after entering information in the form. When
this control is clicked, the page must extract the values
from the form elements and invoke the sumColumn
method. You should not actually submit the form to the
server: everything will happen on the browser.sumColumn
method.
You may add additional styles to tableScan.css
if needed.
parseInt
, parseFloat
, isNan
.cells
firstChild
nextSibling
rows
tagName
textContent
console.log
is very useful for
debugging. It takes a string argument, which it prints to the Javascript
log. You can display this log with "Tools -> JavaScript console" in the
Chrome control menu. If you are
having trouble figuring out what is happening in your Javascript,
sprinkle console.log
statements around your code so you
can see which code is being executed.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.).
Use the standard class submission mechanism
to submit the entire project6
directory.