Search for a Friend


No error message but why do I get duplicate return of Steve's contact information? Also, in the line of code ' if (friends[key].firstName === name) ', where do we define before what a 'name' is? How does the program know that 'firstName' is a name? Thank you!

Replace this line with your code. 
var friends = {
    bill: {
        firstName: "Bill",
        lastName: "Johnson",
        number: "1234567890",
        address: ['999 hello way','rock','MD', '20854']
    steve: {
        firstName: "Steve",
        lastName: "Jay",
        number: "1234567899",
        address: ['998 hello way','rock','MD', '20854']

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];


I am not sure about the duplicate but to answer your second question: in your function search, the variable name is passed through. The if statement simply checks if the first name of each person in the list of friends is equal to the name variable that you pass through as an argument.


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