Contact List Search Function


#1



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


While trying to do this search function I get the error "Oops, try again. It looks like your search function doesn't return contact information for Steve." I added a else statement to see if key is retrieving any variables. It pulls bill and steve then errors out. Not sure whats wrong with my code please help haha.


var friends = {
    bill: {firstName:'Bill', 
    lastName: 'Gates', 
    number:"(905) 873-6472",
    address: ['One Microsoft Way', 'Toronto', 'ON', '12345']
    },
    steve: {firstName:'Steve', 
    lastName: 'Jobs', 
    number:"(905) 873-6619",
    address: ['One Apple Way', 'Toronto', 'ON', '678910']
    }
};// end of friends 

var list = function(friends){
    for(var names in friends){
        names[friends];
       console.log(names);
    }
}//end of list 

var search = function(name) {
    for(var key in friends) {
        if(friends[key].firstName === key){
            console.log(friends[key]);
            return friends[key];
        }
        else
        {
            //added for trouble shooting
            // key is grabbing the name 
            // but nothing else
            console.log(key);   
        }
    }   
}// end of search function
list[friends];
search("steve");


#2

It might be because you capitalized Steve in the first few lines but the very last line you just put it as a lower case steve?


#3

That was not it but thanks to you I though of a new area of code to look at. I was calling key where I should have been calling the name function. Thanks for the help!!


#4

I don't understand how this part works, could someone explain this to me?