Search function not working


#1


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


Error = "Oops, try again. It looks like your search function didn't log "Bob Jones" to the console. Did you remember to call search after you defined it?".

I've checked small syntaxes to see if maybe I was not putting in the right array element or the wrong object property but it all checks out. So why doesn't my search function work????


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]);
	}
};
/*console.log(contacts[0].lastName);
printPerson(contacts[0]);*/

/*Create a search function
then call it passing "Jones"*/
function search(lastName) {
    var contactsLength = contacts.Length;
    for (i = 0; i < contactsLength; i++) {
        if (contacts[i].lastName === lastName) {
            printPerson(contacts[i]);
        } else {
            console.log("nope");
        }
    }
};

search("Jones");


#2

this line:

var contactsLength = contacts.Length;

.length is a built in function, which is case sensitive


#3

Argh!!! I hate it when a function isn't working just because of some tiny typo!!!

Thanks so much! No more hair being ripped out :smiley:


#4