7. Search for a Friend not finding Steve


#1

https://www.codecademy.com/courses/javascript-beginner-en-3bmfN/0/7?curriculum_id=506324b3a7dffd00020bf661#

Can't get it to work.
Oops, try again. It looks like your search function doesn't return contact information for Steve.

var friends = {
    bill: {
        firstName: "Bill",
        lastName: "Gates",
        number: "(206) 555-5555",
        address: ["400", "computer", "drive"]
    },
    steve: {
        firstName: "Steve",
        lastName: "Jobs",
        number: "(408) 555-5555",
        address: ["800", "laptop", "road"]
    }
};

var list = function(friends) {
    for (var key in friends) {
        console.log(key);
    }
}

var search = function(name) {
    for (var key in friends) {
        if (friends[key].firstName === name) {
            console.log(friends[key]);
            return friends[key];
        } else {
            return("couldn't find them");
        };
    }
}


#2

HI you don't need of the else statement in this case

else {
    return("couldn't find them");
};

#3

Hello @mastercoates, it seems you have placed your semicolon in the wrong place. The semicolon should be placed at the end of the function declaration, not at the end of the if..else statement. Fix this and your code should work.


#4

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