Advertisement
gnamp

still dunno

Feb 10th, 2012
528
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. var bob = {
  2.     firstName: "Bob",
  3.     lastName: "Jones",
  4.    
  5.     phoneNumber: "(650) 777 - 7777",
  6.     email: "bob.jones@example.com"
  7. };
  8.  
  9. var mary = {
  10.     firstName: "Mary",
  11.     lastName: "Johnson",
  12.    
  13.     phoneNumber: "(650) 888 - 8888",
  14.     email: "mary.johnson@example.com"
  15. };
  16.  
  17. var contacts = [bob, mary, newContact];
  18.  
  19. function printPerson (contact) {
  20.     console.log(contact.firstName + " " + contact.lastName);
  21. }
  22.  
  23. function list (){
  24.     numberOfItems = contacts.length;
  25.     for (i=0; i<numberOfItems; i++){
  26.         printPerson(contacts[i]);
  27.     }
  28. }
  29.  
  30. function search(lastName){
  31.     numberOfContacts = contacts.length;
  32.     for (i=0; i<numberOfContacts; i++){
  33.         if(lastName === contacts[i].lastName){
  34.         return printPerson(contacts[i]);
  35.         }
  36.     }
  37. }
  38.  
  39. function add(firstName, lastName, email, telephone){
  40.     var newContact = new Object();
  41.     newContact.firstName = firstName;
  42.     newContact.lastName = lastName;
  43.     newContact.email = email;
  44.     newContact.telephone = telephone;
  45.    
  46. contacts[contacts.length] = newContact;
  47. }
  48.  
  49. var firstName = prompt("First Name?");
  50. var lastName = prompt("Last Name?");
  51. var email = prompt("Email?");
  52. var telephone = prompt("Telephone?");
  53. list();
  54. search("Jones");
  55. add(firstName, lastName, email, telephone);
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement