Finding that Special someone


#1


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


Hello codecademy community,
for this exercise I am having a somewhat issue, the console is printing all contacts, however, I believe it is supposed to print all contacts Bob Jones again. It says I am correct, is this suppose to happen?


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() {
	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");


#2

Remember that = !== ===!

In your search function, you have the if condition as lastName = contacts[i].lastName... Make sure that you're actually telling it that "If lastName is equal to ..."


#3

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