I keep geting friends undifined


#1

I cand figure out how to write anew msh so Im writing my question as a reply:
I keep geting friends undifined.
what is wrong here? any help please?

var friends = {
bill: {
firstName: 'bill',
lastName: 'Gates',
number: '123456',
address: ["ehud", 135, "kfar haoranim"]
},
steve: {
firstName: 'steve',
lastName: 'Jobbs',
number: '123456',
address: ["ehud", 135, "kfar haoranim"]
}
};

console.log("friends =" + friends);

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

var f = function() {
console.log("friends in f =" + friends);
}

var search = function (name) {
console.log("friends 0 is " + friends.bill + "\n");
for (var i in friends) {
console.log("i=" + friends[i]);
console.log("name is " + name + "\n name in list is " + friends[i].firstMame);
if ( name === friends[i].firstMame ) {
console.log(friends[i]) ;
return friends[i];

    }
}

}

console.log("friends out =" + friends);
f();
search('bill');


Search for a friend; One Bill, Two Steve
#2

@yasminamran


How to format your code

After you post a few times you'll be able to see this one, too:


Regarding your question:

I keep geting friends undifined.

I don't get this error.

However, I do get this one:

name in list is undefined

You put a lot of console logs, which is helpful to pinpoint the error :slight_smile: in the code:

name in list is " + friends[i].firstMame

See the problem?

frisby