Help with my code! 7/8 and 8/8


#1

Hi all my code is generally working but i'm pretty sure the output is not correct as it is bringing out the names of the objects containing addresses as well as the address of what I searched.

Here is my code:
function list(friends){
for(var i in friends){
console.log(i)
}
};
function search(name){
for (var key in friends){
if('Bill'){
return friends.bill
} else if ('Steve'){
return friends.steve
} else {
return "I don't have the contact information for that person";
}
}
}

list(friends);
search(friends.bill)
var friends={};
friends.bill={};
friends.bill.firstName='Bill',
friends.bill.lastName='Gates',
friends.bill.number=934-350-3823,
friends.bill.address=['ABC, Easier than 123','Do Rey Me', 'La Tee Dee'];

friends.steve= {};
friends.steve.firstName='Steve',
friends.steve.lastName='Jobs',
friends.steve.number='023-348-6578',
friends.steve.address=['1 Crazy genius' ,'Cali'];

Also how could I make it look neater as shown in 8/8... Using only what we have learnt on this course so far?

Thank you for your time! :smiley:


#2

i did the function like this for a better format
var search = function(name) {
for(var key in friends){
if(friends[key].firstName === name){
console.log("Name: " + friends[key].firstName + " " + friends[key].lastName);
console.log("Number: " + friends[key].number);
console.log("Adress: " + friends[key].address[0] + ", " + friends[key].address[1] + ", "+ friends[key].address[2] + friends[key].address[3]);
return friends[key];
}
}
};