We made a Friend


#1

https://www.codecademy.com/courses/building-an-address-book/0/6?curriculum_id=506324b3a7dffd00020bf661#

It won't let me pass.


var bob = {
    firstName: "Bob",
    lastName: "Jones",
    email: "bob.jones@example.com",
    phoneNumber: "(650) 777-7777"
};

var mary = {
    firstName: "Mary",
    lastName: "Johnson",
    email: "mary.johnson@example.com",
    phoneNumber: "(650) 888-8888"
};

var contacts = [bob, mary];

function printPerson(person) {
    console.log(person.firstName + " " + person.lastName);
}

function list() {
	var contactsLength = contacts.length;
	for (var i = 0; i < contactsLength; i++) {
		printPerson(contacts[i]);
	}
}

/*Create a search function
then call it passing "Jones"*/

function search(lastName){
    var contactsLength = contacts.length;
    for (i = 0; i<contactsLength; i++){
      if (lastName===contacts[i].lastName) {
        printPerson(contacts[i]);  
      }
        
    }
}

function add(firstName, lastName, email,phoneNumber){
    var newContact = new Object();
    newContact.firstName = firstName;
    newContact.lastName = lastName;
    newContact.email = email;
    newContact.phoneNumber = phoneNumber;
    
    contacts.push(newContact);
    
}

add("Josh","Young","egeivv@gman.com","905-394-2431");

console.log(contacts);


#2

here:

console.log(contacts);

don't log contacts to the console, we build a function for that, call the list function instead


#3

This topic was automatically closed 7 days after the last reply. New replies are no longer allowed.