6/6 "We made a friend"


#1



Hello.This is my code.When i prees "Save and Submit" it says "Oops, try again. It looks like your new contact doesn't have a firstName property."
What's wrong?


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]);
        }
    }
};
search("Jones");
function add(firstName, lastName, email, phoneNumber) {
    var contact = {
        firstName: firstName,
        lastName: lastName,
        email: email,
        phoneNumber: phoneNumber
    }
    contacts[contacts.length] = contact;
};
add("Jake","Gyllen","222-555-444","jake@exa.com");
list();


#2

@warriorcodes,
The error is caused,
much earlier....
look at

var contacts = [bob, mary];
//var contacts = [bob, mary, contacts];
console.log( contacts );

#3

I don't get it....What do i do and why?


#4

@warriorcodes,

You will have to change your code !!!!!

Change your

var contacts = [bob, mary, contacts];

into

var contacts = [bob, mary];

#5

Actually, to var contacts = [bob, mary];