7. Search for a friend


#1



Hi, could anyone kindly let me know what I am doing wrong?

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


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


var friends = {
    
    bill: {
        firstName: "Bill",
        lastName: "Gates",
        number: "(206) 555-5555",
        address: ['One Microsoft Way', 'Redmond', 'WA', '98052']
    },
    
    steve: {
        firstName: "Steve",
        lastName: "Jobs",
        number: "(204)444-4444",
        address: ['Apple Way', 'Bluemond', 'NY', '98053']
    }
};

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(frineds[key]);
            return friends[key];
        }
    }
};


#2

HI this line

console.log(frineds[key])

you wrote frineds instead of friends


#3

I guess the spelling of friends there isn't consistent.

I've corrected below:

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

#4

That was a simple mistake... Thank a lot!


#5

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