Doesn't log Contact Info for Steve But it Did?


#1

It actually logged steve's info twice and Bill's once, what did i do wrong? I get an error saying it didnt log steve's
var friends={
bill: {
firstName:"Bill",
lastName:"Gates",
number:"8",
address:["Billionaire Drive"]
},
steve: {
firstName:"Steve",
lastName:"Jobs",
number:"7",
address:["Money Drive"]
}
};
var list=function(friends){
for (var bill in friends) {
console.log(bill)
}
}
var search=function(name) {
for (var address in friends) {
if (friends[address].firstName===name) {
console.log(friends[address])
}
}
};


#2

I Have almost same problem..

Here is my Code..

var name = prompt("To whom you are searching for?");
var friends = new Object();
friends.bill = new Object();
friends.bill.firstName = "Bill";
friends.bill.lastName = "Gates";
friends.bill.number = "(555) 555-5555"
friends.bill.address = ['address blah']
friends.steve = new Object();
friends.steve.firstName = "Steve";
friends.steve.lastName = "Jobs";
friends.steve.number = "(555) 555-5556"
friends.steve.address = ['address blah']

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

var search = function(name) {
for (var firstName in friends) {
if (friends.firstName === name) {
console.log(friends.firstName);
return friends;
}
else
{
console.log("Sorry! Not a friend!");
break;
}
}
};

search();