What's wrong with my code.please explain?


#1

var friends = {
bill:{
firstName: "Bill",
lastName: "Johson",
number: "09157757865",
address: ['One Microsoft Way','Redmond','WA','98052']
},
Steve: {
firstName: "Steve",
lastName: "Rock",
number: "09157735461",
address: ['Bonaficio','taguig','manila','98602']
}
};
var list = function (friends){
for(var j in friends){
console.log(j);
}
};
var search= function(name){
for(var firstName in friends){
if(friends[firstName].firstName===name){
console.log(friends[firstName]);
return friends[firstName];
}else{
return"sorry";
}
}
};
search(bill);


#2

Not sure what exact lesson you are on...
edit: removing code.


#3

thanks but it still showing an error as "It looks like your search function doesn't return contact information for Steve.". This lesson is search for a friend.


#4

var friends needs closing at the top ={}
Should be friends.bill = {
Look closely above steve. You can see a comma also you should use friend.(name here)
Example
friends.steve = {
As well as Bill, you need steve to be the same as bill
Get rid of the first { underneath the address for steve as it is un-needed.
As well as missing a function for an object
Example
var list = function (obj) {
Should be for(var prop in friends){
as well as under it changing to
if(friends[prop].firstName === name)
You then need to move console log later so after the statement before put a
{
the console log etc.

after console log put a
}
}
};
As well as your search being bill when it should be steve.
You should have a list for friend like list(friends)

return friends
and
console.log

should be
return friends friends[prop];
console.log (friends[prop]);

You miss most of the logical things like these = most of the time anything else that needs fixing should be decently logical,