Search a list


i can't find where i did wrong in my code, can anyone help me figure it out?

var friends = {
    bill: {firstName: "Bill",
    lastName: "Allen",
    number: "0910-453-746",
    address: ["China", "Guangzhou", "Penyu District"]},
    steve: {firstName: "Steve",
    lastName: "Kao",
    number: "0909-412-444",
    address: ["Taiwan", "Taipei City", "Chungzhang District"]}

var list = function (friends) {
    for (var key in friends) {

var search = function(name) {
    for (var key in friends ) {
        if (friends[key].firstname === name) {
            return friends[key];
        } else { return "invalid" 



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

It should be friends[key].firstName

also you need to remove the else statement.A function ends at that moment whenever a return keyword is reached.


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