It prints all the names instead of just the searched name


#1


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


If I search for July, it prints all the names and all the details of the other names? I just want the searched name to be printed out.

var friends = {
    bill: {
        firstName: "Bill",
        lastName: "Gates",
        number: "111",
        address: ["1", "Micro"]
    },
    steve: {
        firstName: "Steve",
        lastName: "Jobs",
        number: "222",
        address: ["2", "App"]
    },
    
       july: {
        firstName: "July",
        lastName: "Itchon",
        number: "21651685384",
        address: ['Taguig Manila','Sony','Phls','Japan']
    }
};

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

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


search("July");


#2

@elderaranda
You are confused
by extra output generated by the code-checker....

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 try it by using

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

#3

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