Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- var bob = {
- firstName: "Bob",
- lastName: "Jones",
- phoneNumber: "(650) 777 - 7777",
- email: "bob.jones@example.com"
- };
- var mary = {
- firstName: "Mary",
- lastName: "Johnson",
- phoneNumber: "(650) 888 - 8888",
- email: "mary.johnson@example.com"
- };
- var contacts = [bob, mary];
- function printPerson (person) {
- console.log(person.firstName + " " + person.lastName);
- }
- function list (){
- numberOfItems = contacts.length;
- for (i=0; i<numberOfItems; i++){
- printPerson(contacts[i]);
- }
- }
- function search(lastName){
- numberOfContacts = contacts.length;
- for (i=0; i<numberOfContacts; i++){
- if(lastName === contacts[i].lastName){
- return printPerson(contacts[i]);
- }
- }
- }
- function add(firstName, lastName, email, telephone){
- var newContact = new Object();
- newContact.firstName = firstName;
- newContact.lastName = lastName;
- newContact.email = email;
- newContact.telephone = telephone;
- contacts[contacts.length] = newContact;
- }
- var firstName = prompt("First Name?");
- var lastName = prompt("Last Name?");
- var email = prompt("Email?");
- var telephone = prompt("Telephone?");
- list();
- search("Jones");
- add(firstName, lastName, email, telephone);
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement