Contact list 7 - issue with search function


#1

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

when I search for steve or bill at the end. it gives me information for both, not just the one I am searching for. It doesn't give me any info on the test friend though, but when I search out "Test", it gives me info on all 3. What's wrong with this code? It's allowing me to proceed to the next level for some reason.

I have gone back to the first exercise and looked at the prewritten code and tried to use the word prop instead of firstName in both search function, but then I get an error saying prop is not defined...it's not defined in the first exercise either, but seems to work for it.

edit - when I decided to just go ahead and proceed to the next level and then ran the function...it just showed the info of the test friend I asked for...why didnt it work properly in number 7 though?

var friends = {
    bill: {
        firstName: "Bill",
        lastName: "Billington",
        number: "416-734-7907",
        address: ["1833", "Misthollow Drive", "Pickering", "Ontario", "L1X0A7"]
        },
    steve: {
        firstName: "Steve",
        lastName: "Johnson",
        number: "783538-7307",
        address: ["1C", "Manor Road", "Wallington", "London", "SM6 0BW"]
        },
    testFriend: {
        firstName: "Test",
        lastName: "Friend",
        number: "123-456-7891",
        address: ["13 Oriel Court", "47 Lansdowne Road", "Croydon", "London", "CR0 2BE"]
        }
};

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

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

list(friends);
search("Test");

#2

@faar23,

In some sections of this course, the course-checker Display's data
this you could then identify by placing two EXTRA code-line's:
console.log( "== My End ==" );
console.log( "== All that is displayed now, is the course-checker ==" );

Thus im your code use

list(friends);
search("Test");
console.log( "== My End ==" );
console.log( "== All that is displayed now, is the course-checker ==" );