What am i doing wrong?


#1


Contact List: Search for a friend.


Oops, try again. It looks like your search function doesn't return contact information for Steve.


var friends = new Object(); {

friends.bill = new Object(); {
    friends.bill.firstName = "Bill",
    friends.bill.lastName = "Johnson",
    friends.bill.number = "(404) 364-2836"
    friends.bill.address = ["132 Edgewood Ave", "Atlanta", "Ga", "30303"]
};

friends.steve = new Object(); {
    friends.steve.firstName = "Steve",
    friends.steve.lastName = "Jobs",
    friends.steve.number = "(404) 384-2836"
    friends.steve.address = ["22 Peachtree Court", "Atlanta", "Ga", "30303"]
};

};
 var list = function (friends) {
    for (var friend in friends) {
        console.log(friend); 
    } 
 };
 
 var search = function (name) {
    for (var key in friends) {
        if (friends[key].firstname === name) {
            console.log(friends[key]);
            return friends[key];
        }
    } 
 }
 
list(friends);  
search("Steve");


#2

the problem is in your object themselves:

var friends = new Object(); {

friends.bill = new Object(); {
    friends.bill.firstName = "Bill",
    friends.bill.lastName = "Johnson",
    friends.bill.number = "(404) 364-2836"
    friends.bill.address = ["132 Edgewood Ave", "Atlanta", "Ga", "30303"]
};

friends.steve = new Object(); {
    friends.steve.firstName = "Steve",
    friends.steve.lastName = "Jobs",
    friends.steve.number = "(404) 384-2836"
    friends.steve.address = ["22 Peachtree Court", "Atlanta", "Ga", "30303"]
};

};

this looks likes a mix of the literal notation and the object constructor. please use one of those methods to make your objects, not tangle them together


#3

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