Contact list


#1

https://www.codecademy.com/en/courses/javascript-beginner-en-3bmfN/0/7?curriculum_id=506324b3a7dffd00020bf661

Hello, I have been trying to pass this exercise for a long time now but i cannot find my mistake. I get the error "Oops, try again. It looks like your search function doesn't return contact information for Steve". Here is my code.

var friends={
    bill:{
        firstName:"bill",
        lastName:"guy",
        number:"555",
        address:["guy street"]
        },
    steve:{ firstName:"steve",
        lastName:"connor",
        number:"911",
        address:["beach street"]
        }
}
var list=function(friends){
    for (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];
        }else{
            return"no match";
        }
    
    }
}
search("steve");

I tried removing the else{return "no match"} part in my code and i am able to get the correct message to appear on the black screen.However, the same error message keeps appearing. I would appreciate if someone could explain to me why this code does not work. Thank you very much in advance!


#2

Hello @erador,

Try putting the firstName properties of both of these as capital letters. That should fix your problem...


#3

var friends = {
bill: {
firstName: "Bill",
lastName: "Gates"
},
steve: {
firstName: "Steve",
lastName: "Jobs"
}
};

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

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

};
search("Steve");


#4

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