0

Thanks for having a look at my question! I'm trying to complete the JavaScript course in codecademy and this has me stumped. I can't even find help in the codecademy forums. I am trying to figure out why "Bob Jones" isn't logged to the console. Any help is greatly appreciated. Here is my code:

var bob = {
    firstName: "Bob",
    lastName: "Jones",
    phoneNumber: "(650) 777-7777",
    email: "[email protected]"
};

var mary = {
    firstName: "Mary",
    lastName: "Johnson",
    phoneNumber: "(650) 888-8888",
    email: "[email protected]"
};

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

1 Answer 1

2

The problem is that JavaScript is case sensitive and the array length is available under the lengthproperty, not Length.

P.S. learn to use a debugger.

Sign up to request clarification or add additional context in comments.

2 Comments

Thank you so much Amit! Downloading firebug as I type this comment. I really appreciate your help.
@JenKutler: if this answer solved your problem, please remember to mak it as accepted by clicking on the tick icon on its left. Thank you!

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.