Something tells me I did something wrong


#1

I just finished 7/8 , but something tells me this isnt right, as it just repeated

{ firstName: 'Bill',
lastName: 'Gates',
number: '888888888',
address: [ 'Bill Gates', 'GateS', 'GATES' ] }

3 times. Can someone explain how I was actually meant to do this?

Code:

var friends = {
bill: {
firstName: "Bill",
lastName:"Gates",
number:"888888888",
address: ["Bill Gates", "GateS", "GATES"]
},
steve: {
firstName: "Steve",
lastname: "Jobs",
number:"9494949494994",
address: ["Apple Maps", "Seventeen"]
}
};

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

var search = function(name){
for(var key in friends){

        console.log(friends[key]);
        return friends[key];
    };
};

#2

This is my code:

var friends = {};
    friends.bill = {
        firstName: "Bill",
        lastName: "Parl",
        number: "(666) 452-6138",
        address: ['Valley Way' , 'Montey', 'CA' , '94568']
};
    friends.steve = {
        firstName: "Steve",
        lastName: "Unot",
        number: "(334) 614-7823",
        address: ['Dell City' , 'Vancouver', 'CA' , '97358']
};

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

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

list(friends);
search("Steve");
search("Bill");

This code over here first gives the two names (bill and steve), and then tells the information of Steve and Bill, and does it again.

I don't know if it's supposed to be like this or not, but I know that it should not repeat the same thing 3 times. Try it, and see if you can find out why. There's alot more people that are more codetastic than me. :smiley: