5. Finding that Special Someone


#1



I think my code is not correct. Could anyone kindly point out where I am doing wrong?

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


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"*/

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

search("Jones");


#2

when comparing inside a if condition, use two or three equal signs, a single equal sign means assign value to variable:

 if (lastName = contacts[i].lastName)

#3

Oh yes, I always do that... Thanks a lot for your help!!


#4

was just going to say it is not the first time i see you make this mistake.


#5

Very true. Thanks for your help always...!