Search For A Friend


#1

Getting this error:
It looks like your search function doesn't return contact information for Steve.

Here's my code:
var friends=new Object();
friends.Steve=new Object();
friends.Bill=new Object();
friends.Steve.firstName="Steve";
friends.Steve.lastName="Jobs";
friends.Steve.number="(123)-555-5555";
friends.Steve.address= ['One Microsoft Way','Redmond','WA','98052']
friends.Bill.firstName="Bill";
friends.Bill.lastName="Gates";
friends.Bill.number="(321)-555-5555";
friends.Bill.address= ['Two Station','Arlington','VA','25803']
var list = function (friends) {
for (var key in friends){
console.log(key);
}
};
var search = function(name) {
for (var C in friends) {
if(friends[C].firstname === name) {
console.log(friends[C]);
return friends[C];
}
}
};
search("Steve");
search("Bill");


#2

var search = function(name) {
    for (var i in friends) {
        if(friends[i].firstname === name) { //The 'Name' in 'firstName' isn't capitalised
            console.log(friends[i]);
            return friends[i];
        }
    }
};

(See comment in code)

It sucks that such small errors can stop your code from working, haha


#3

This topic was automatically closed 7 days after the last reply. New replies are no longer allowed.