5. Finding that special someone


#1


Replace this line with your code.


#2

I don't understand why I'm not able to start a new topic in this website. My old Macbook? It says 'replace this line with your code' but I cannot edit the line at all or write anywhere else, so I have to reply to my own topic. But anyway...

This is the code I've made for this task, I'm not quite sure what is wrong. please help.

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(var i = 0; i < contactsLength; i++) {
        if(contacts[i].lastName === lastName) {
            console.log(contacts[i]);}
        else{console.log("No contacts found.");   } 
        };
        };

search("Jones");

#3

from the instructions:

Have the function run printPerson on the person if and only if the lastName property of the person matches the lastName argument.

Now lets look at your code:

console.log(contacts[i])

you log contacts[i], you should call printPerson to log Bob Jones to the console


#4

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