7/8 PLEASE HELP. Really struggling to understand this


#1

here is my code. What is wrong?

var friends = new Object();

friends.bill = new Object ();
friends.steve = new Object ();
friends.jason = new Object ();

var friends = {
bill: {
firstName: "Bill",
lastName: "Gates",
number: "(206) 555-5555",
address: ["1 far drv hoopers"]
}
};

var friends = {
steve: {
firstName: "Steve",
lastName: "Jobs",
number: "(206) 777-5555",
address: ["2 far drv hoopers"]
}
};

var friends = {
jason: {
firstName: "Jason",
lastName: "Johns",
number: "(206) 666-5555",
address: ["3 far drv hoopers"]
}
};

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

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");


#2

Hi @digitalslayer84339

I corrected your code :

var friends = {
bill: {
firstName: "Bill",
lastName: "Gates",
number: "(206) 555-5555",
address: ["1 far drv hoopers"]
},
steve: {
firstName: "Steve",
lastName: "Jobs",
number: "(206) 777-5555",
address: ["2 far drv hoopers"]
},
jason: {
firstName: "Jason",
lastName: "Johns",
number: "(206) 666-5555",
address: ["3 far drv hoopers"]
}
};

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

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

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

Do you have questions ?