7/8 search function doesn't word, even tried copy/pasting others' solutions


#1

Hi, if someone could please explain what I'm doing wrong I would really appreciate it. I've read all the posts I could find on this section and have copied several different solutions, and still every time it runs it says "It looks like your search function doesn't return contact information for Bill." Here is my code:

var friends = new Object();
friends.steve = new Object();
friends.bill = new Object();

friends = {
    bill: {
        firstName: "Bill",
        lastName: "Brown",
        number: "444-555-6666",
        address: ["456 Brown St.", "St. Louis", "MO", "63051"]
    }
};

friends = {
    steve: {
        firstName: "Steve",
        lastName: "Smith",
        number: "777-888-9999",
        address: ["789 Smith St.", "Alamogordo", "NM", "78900"]
    }
};

var list = function (friends) {
    for (var key in friends) {
        console.log(key);
    }
};

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

#2

Just try to use Bill Gates instead of Brown and also change to Jobs.
If it the same problem still persisting then reload the browser.

var friends = {
bill: {
    firstName: "Bill",
    lastName: "Gates",
    number: "00123456789",
    address: ['Microsoft Way' , 'Louzani']
    },
steve: {
    firstName: "Steve",
    lastName: "Jobs",
    number: "00987654321",
    address: ["Iphone Address" , 'California']
    }
};var list = function(obj) {
for (var sin in obj) {
    console.log(sin);
    }
};    
var search = function(name) {
for (var sin in friends) {
    if (friends[sin].firstName === name) {
        console.log(friends[sin]);
        return friends[sin];
        }
    
    }
};

list(friends);
search("Steve"); //**Guess You Should add those :smile: **
/*

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

list(friends);
search("Steve");
*/


#3

Thank you very much for trying. I copied and pasted a couple different combinations of your code, changed the names, refreshed multiple times, even used two different browsers, still it gives back the same error... if you have any more thoughts it would be appreciated. My code is currently now:

var friends = new Object();
friends.steve = new Object();
friends.bill = new Object();

friends = {
    bill: {
        firstName: "Bill",
        lastName: "Gates",
        number: "444-555-6666",
        address: ["456 Brown St.", "St. Louis", "MO", "63051"]
    }
};

friends = {
    steve: {
        firstName: "Steve",
        lastName: "Jobs",
        number: "777-888-9999",
        address: ["789 Smith St.", "Alamogordo", "NM", "78900"]
    }
};

/* var list = function (friends) {
    for (var key in friends) {
        console.log(key);
    }
};

 var search = function (name) {
    for(var key in friends) {
        if (friends[key].firstName === name) {
            console.log(friends[key]);
            return friends[key];
        }
    }
}; */
var list = function(obj) {
for (var sin in obj) {
    console.log(sin);
    }
};    

var search = function(name) {
for (var sin in friends) {
    if (friends[sin].firstName === name) {
        console.log(friends[sin]);
        return friends[sin];
        }
    
    }
};
list(friends);
search(name);

#4

var friends = {
bill: {
firstName: "Bill",
lastName: "Gates",
number: "555-555-5555",
address: ['Highway to ■■■■', 'Portland', 'OR', '66666'],
},
steve: {
firstName: "Steve",
lastName: "Jobs",
number: "666-666-6666",
address: ['Heavens Gates', 'Abrahams', 'BO', '55555']
},
};
var list = function(friends) {
for(var name in friends) {
console.log(name);
};
};
list(friends);
var search = function(name) {
for(var key in friends) {
if(friends[key].firstName === name) {
console.log(friends[key]);
return friends[key];
}
}
};

here is my code. it worked for me


#5

var friends = new Object();
friends.bill = new Object();
friends.steve = new Object();

friends.bill.firstName = "Billy";
friends.bill.lastName = "Bravo";
friends.bill.number = 2;

friends.steve.firstName = "Steve";
friends.steve.lastName = "Stell";
friends.steve.number = 5;

friends.bill.address = ['calle', 'surimana',482,'san luis'];
friends.steve.address = ['jiron','Pérez de Tudela',2770,'Lima'];

var list = function (friends) {

for (var name in friends){
    console.log(name);
}

};

list(friends);

console.log(friends);

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

search('bill');

list(friends);

console.log(friends);

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