7. Search for a friend


#1



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


ReferenceError: steve is not defined


var friends = {
    bill: {
        firstName: "Bill",
        lastName: "Gajic",
        number: "062/232-448",
        address: ["Milosa Obilica", 145, "Nova Pazova", 22330]
    },
    steve: {
        firstName: "Steve",
        lastName: "Jovancevic",
        number: "064/895-136",
        address: ["Boska Buhe", 104, "Nova Pazova", 22330]
    }
};

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

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

};
list(friends);
search(steve);


#2

steve needs to be in double quotes (when searching )


#3

Hey zainabrawat,
Thanks, it worked out! But im not sure the output i get is what i actually want... I'll show you what it printed:


#4

Which part you didn't expect?

When you console.log an object you will get all the brackets, etc. If you want to instead print only the keys or values then you have to loop through them one by one. -@albionsrefuge Thank you


#5

Hello,

Allright, i think i get it now. Thanks a lot for your help!

Regards