Threesuns

Email

Contact

All Semesters

Semesters

All Courses

Courses

Scripting (Online)

CSYS2033

3 credits

Labs

Person Object

Lab

100 points

Requirements

Page is well formed and valid10
Person constructor function created10
Function to accept inputs was created10
Display method was created10
Person objects allow blank names but not blank phone number parts20
Display function shows names formatted correctly20
Display function shows phone numbers correctly20
Total100 pts

Objective

To work with creating a custom object and methods.

Instructions

For this lab you will be writing a script that will allow a user to enter the first name, last name, area code, and phone number of a person which will then be stored in an object and displayed on the page.

To do this you will need to create a constructor function for Person which will contain the attributes mentioned above about that person. A person object created with this constructor function can have a first and last name or either of the names can be left blank. The person can also have a phone number consisting of an area code and number but if either of the two parts of the phone number are missing the incomplete phone number should not be stored in the object.

In addition to the Person constructor function you should also write a stand-alone function (not a method of the object) that prompts the user for the four pieces of information about the person and then allows for those values to be used to make the Person object.

A method should be created for the Person object called display that will show the information stored inside that Person object. The display method should show the last name followed by a comma and then the first name if both names are available. If either name is missing, the one name that is available should be displayed without a comma, and if neither name is available the display method should show "Unknown" in place of the names.

If the entire phone number was entered the display method should show it in (999) 999-9999 format. If the entire phone number wasn't entered then nothing should be shown in its place.