7. Search for a friend, help!


#1


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


TypeError: Cannot read property 'firstName' of undefined

Oops, try again. Did you create a function called search?


var search = function(name) {
    for(var key in name) {
        if(friends[key].firstName === name) {
            return friends[key]
            } else {
                return "Friend was not found";
                }
            };
};

search("Steve");


#2

Here. You need to replace 'key' and 'name' with the appropriate terms. The hint does this to ensure user participation.

var search = function(name) {
for (firstName in friends) {
if (friends[name].firstName === name) {
console.log(friends[name]);
return friends[key];
}
};

BTW, F1rst P0st!


#3

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