6.We Made a Friend! returning undefined, undefined


#1


6.We Made a Friend


My code returns this:

Bob Jones
Mary Johnson
undefined undefined
Albert Apple

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, contacts];

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 (var i = 0; i < contactsLength; i++) {
        if(lastName === contacts[i].lastName) {
            printPerson(contacts[i]);
        }
    }
};

function add(firstName, lastName, email, phoneNumber) {
   this.firstName= firstName,
   this.lastName= lastName,
   this.email= email,
   this.phoneNumber= phoneNumber
   
   contacts[contacts.length] = this;
};
    
    
add("Albert", "Apple", "applealbert@example.com", "(777) 777-7777");
list();

#2

Remove last element from an array. This element is not defined.


#3

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