7/8 Can someone please help me and find the error in the code?


#1

var friends = new Object();
friends.bill = new Object();
friends.steve = new Object();
var friends = {
bill: {
firstName: "Bill",
lastName: "Gates",
number: "(206) 555-5555",
address: ['One Microsoft Way','Redmond','WA','98052']

steve: {
    firstName: "Steve",
    lastName: "Hills",
    number: "(206) 555-5555",
    address: ['Yellow Hills', 'Churchhill', 'NSW','20381']
}

}
};

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

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

l actually found the error myself, it was actually hidden well in the code. All l had to fix up, was to add a bracket after bill's address like this:

var friends = {
bill: {
firstName: "Bill",
lastName: "Gates",
number: "(206) 555-5555",
address: ['One Microsoft Way','Redmond','WA','98052']
}, -----This was the small thing l was missing out on.

steve: {
    firstName: "Steve",
    lastName: "Hills",
    number: "(206) 555-5555",
    address: ['Yellow Hills', 'Churchhill', 'NSW','20381']
}

};


#3

Hi friend.... it's working

var friends={};
friends.bill={
firstName: "Bill",
lastName: "Gates",
number: "(111) 11-1111",
address:"add bill gates",
},
friends.steve={
firstName: "Steve",
lastName: "stv",
number: "(222) 22-2222",
address:"add steve bill",
}
var list = function(key)
{
for (var key in friends)
{

        "steve",
        "bill"
    }
}

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

};
search("Steve");
search("Bill");


#4

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