BIT 116 - Scripting
Assignment 2Due: Thursday, January
25th
A Personalized Table Generated from User Input
This is another web page whose content is provided by the user via
prompt() and confirm() boxes. This time, the page
being created is an address book. The information provided by the user is the
names, addresses, telephone numbers, email addresses, and children's names of
their relatives, friends, and contacts. Your page will use this information to
generate an html table that displays a personalized address book for the user.
Here is a sample of what the output of the page could look like:
You are free to format the table to your own tastes, but it should
display the appropriate information provided by the user.
Here is the sequence of events that the user goes through when
using this page:
- The user is asked whether or not they'd like to add a name
to the address book.
If the user wants to add a name to the book, proceed to step
2. If the user doesn't want to add a name to the book,
proceed to step 4.
- The user is asked to provide the name, address, telephone number,
email address, and all of the children's names of the next
entry in the book.
Note: The user is not allowed to add duplicate names. You may
match exactly (so that John DOE is considered to be different from
John Doe), or in a case-insensitive manner (so that John DOE is
considered to be the same as John Doe)
Hint: You should use an array for this
Note: When entering the children's names, the user is first
asked how many children there are for this contact, and then
they are asked to enter each name in its own prompt()
box.
- Return to step 1.
- The address book containing all of the information provided by
the user is displayed to the page.
The key to this assignment is that you will not know how many
names the user plans to enter when you are writing this
script.
Restrictions and Requirements:
- Hint:
Use
alert() boxes when you encounter problems with your
script. You can alert the string of html that your script is generating
to see whether or not it is being generated correctly. Use newlines
("\n") in the string to space it out so that it is readable
inside the alert box.
- By the time this assignment is due, you will have seen JavaScript functions, and
so you are expected to make use of them in order to simplify and clarify your
code. One function, named something like GenerateContacts(), should be the only
function that you need to call within the BODY of the document. GenerateContacts()
will, in turn, call any other functions it needs to, in order
to accomplish it's job. It's recommended that you have a GenerateTable()
method, which will concatenate the 'open tag' of the table onto a string
accumulator, and then repeatedly call
GenerateRow(), and finally concatenate the 'closing tag' of the table
onto the accumulator.
GenerateRow() will obtain the user's input, and output an appropriate row.
You're free to deviate from this pattern, but keep in mind that you need to
demonstrate the use of functions to modularize, clarify, and (where possible)
simplify your code, so you'll need to use functions extensively in this
assignment.
- All of the content that is
displayed on the page
must
be generated by a single call to the JavaScript
document.write()
statement. As in assignment 2, you will need to use the string + operator to
create a single string that represents the entire html table. The
expected pattern for this homework assignment is that
GenerateContacts()
will first 'accumulate' the table, and then use a single
document.write()
statement to print out the table at the very end of
GenerateContacts().
Do not hard code an html table into the body of the
page. That will not meet the requirements for this assignment anyway.
- Having a single function (GenerateContacts(), or whatever you want
to name it) generate the table is required.
- By the time this assignment is due, you will have seen JavaScript arrays, which
you are required to use, in order to detect duplicate names.
- You do not need to detect
duplicate names for the children of your contacts. If wish to do this
as an 'extra' feature, you are welcome to do so.
- You are required to define all the code you'll need in a separate .JS
file, and you must include that file via a <SCRIPT> element in the HEAD of the
HTML document. You will then need to call the GenerateContacts()
method in another <SCRIPT> element in the BODY of your HTML document.
- Your .HTML file must work correctly in both Microsoft Internet Explorer
(version 6 or higher) and Mozilla FireFox (Version 1.5 or higher)
What to hand in:
- Your A2_Contacts.html file. You are not provided with a
starting HTML template - you will have to make your own.
Make sure to place the program title, A2.0, into the <title> tag in the <head> of your document for each assignment. Follow it with a “
: ” and your full name. Example:
<title>A2.0: Ian Bansenauer </title>
This is a required part of each submission!
- The separate .JS file that contains your JavaScript code. As long
as there's just one extra file it will be clear that you want me to grade
that one, so you can name it whatever you want.
How To Hand In Your Homework:
We will cover this in class, on the date that this assignment is due.