Scripting (Blended)
3 credits
Page is well formed and valid | 10 |
Person constructor function created | 10 |
Function to accept inputs was created | 10 |
Display method was created | 10 |
Person objects allow blank names but not blank phone number parts | 20 |
Display function shows names formatted correctly | 20 |
Display function shows phone numbers correctly | 20 |
Total | 100 pts |
To work with creating a custom object and methods.
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.