Error: It looks like your search function doesn't return contact information for Steve


#1

I can't figure out what is wrong with this code. I've tried to search on community but I couldn't really find an answer. Please can you help?

var friends = {};
friends.bill = {};
friends.steve = {};

var friends = {
bill: {
firstName: "Bill",
lastName: "Gates",
number: "(206) 555-5555",
address: ['One Microsoft Way','Redmond','WA','98052']
},
steve: {
firstName: "Steve",
lastName: "Jobs",
number: "(206) 555-5500",
address: ['1 Infinite Loop','Cupertino','CA','95014']
}
};

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


#2

Javascript is case sensitive

You didn't capitalize Name in firstName in the if loop of the search function.


#3

But I'm passing the name in search function as "Steve" and not "steve". I tried to covert the case based on your suggestion but it doesn't work.

Any other suggestions please?


#4

No, that's not what I'm referring to...

This property you are referencing in this line:

if(friends[iprop].firstname === name){

it should be firstName, this is because javascript is case sensitive and earlier you entred the propery firstName for your objects.


#5

I need a kick on my back! This is was silly mistake and I spent around 2-3hrs on this one. Many thanks for that.