CS 4, Summer 2006: HW 3, due Friday, July 21
Instructions
The first part of this homework involves writing JavaScript, along
with some HTML to hold it. Follow the same instructions as in HW 1 -- write code by hand, make it easy to read,
print it from the text editor, timestamp it, and upload it to your
private folder.
The second part of this homework is a set of written questions.
You are not required to write your answers in HTML. However, you
should still upload them to your private directory and provide a
printout. Upload your file in a format we can read -- plain text,
HTML, PDF, Word, or RTF. No timestamp is required.
JavaScript Problem [70 points]
Use JavaScript to make an interactive form. The form can be based
on the one you created for HW 2 or on the one from class (Application
to Cross the Bridge of Death), or it can be a new one. Beautification
(tables, style sheets, etc.) is not required. Note that you will no
longer want the Submit input, but instead will have JavaScript handle
the form. As with HW 2, some specific requirements are given below,
but creativity is encouraged and you may incorporate additional
features.
Requirements:
- Take inputs of at least the following types:
- a set of radio buttons, for options from which one can be selected
- a set of check boxes, for options from which zero or more can be selected
- one or more text fields, for more free-form input
- Provide a button for indicating when the form is completed and should
be processed.
- Produce outputs of at least the following types:
- a text or textarea that responds, in a meaningful way, to the
state of the radio buttons and check boxes
For example, the
pizza store could indicate the current total cost, based on the
selected size and toppings. To make a radio button or check box
"respond", specify a JavaScript function for the
onClick attribute.
- a textarea that summarizes all the values entered in the form,
when the "form completed" button is clicked
For example, the
pizza store could generate a receipt, listing the pizza size and
toppings, where it will be delivered, and the total cost.
- One of the inputs should be restricted in which values are
allowed. For example, the pizza store could require that the name and
address not be blank. If the restriction is not satisfied, then when
the "form completed" button is clicked, rather than an order summary,
an error message should be displayed (either in the textarea, or as an
alert).
Written Problems [30 points]
- [20 points]
Write pseudocode for an
algorithm that, given an array in sorted order, returns another array
with only one copy of each value (removing duplicates). For example,
given A = { 1, 2, 2, 3, 3, 3, 4 }, it would create
B = { 1, 2, 3, 4 }.
- [10 points]
You are hired for a 4-week
(20-day) internship at a hot new web company. Would you be better off
to take as your salary (a) $10,000 each day, or (b) $2 the first day,
$4 the second day, $8 the third day, $16 the fourth day, ...,
$2n on the nth day? Justify your
answer.