Help....Not gettting proper output in 'Search for a friend'


var friends = {
        firstName: "Bill",
        lastName: "Gates",
        number: "(206) 555-5555",
        address: ['One Microsoft Way','Redmond','WA','98052']
        firstName: "Steve",
        lastName: "Jobs",
        number: "(408) 555-5555",
        address: ['1 Infinite Loop','Cupertino','CA','95014']
    var list = function (){
        for (var key in friends){
        function search(name){
            for( var key in friends){
                 return friends[key];
            else {
             return "Name could not be found...";   

Error message says 'search function doesn't return contact information for Steve'.


There's a few extra closing braces but other than that the code looks ok though I'm not sure what the lesson's instructions are. Are you supposed to actually call your search function with "Steve" as the supplied argument?

Could you link the lesson instructions please?


Thanks man....
The instruction is as follows...

"Define a function search that takes a single argument, name. If the argument passed to the function matches any of the first names in friends, it should log that friend's contact information to the console and return it."


Can you link the page?


Down below is the link:


Is it passing for you now?


No man...still getting the same error...

And regarding the extra braces you said earlier...I don't find any mistake in it..
Every braces are correctly organised...If not could you spot it please...


Nevermind, I just didn't see it due to the tabbing. For some reason its your else clause. If you delete it the exercise passes.

Incidentally, it seems like given the path through this lesson block, the end solution should have had you use both functions together.

function list(obj) {
    for (var entry in obj) {
        console.log(entry, obj[entry]);

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


Awesome man!!!!!
It passed.......


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