Need Help with the Search Function Excercise!


#1


Currently it is only showing Bill's info and not Steve's. The for loop doesn't seem to actually working.
The error message I got is 'It looks like your search function doesn't return contact information for Steve.'


var friends = {
    bill: {
        firstName: 'Bill',
        lastName: 'Nye',
        number: '(213) 213 - 1234',
        address: ['123 Fake Street', 'Los Angeles', 90019]
        },
    steve: {
        fistName: 'Steve',
        lastName: 'Irwin',
        number: '(323) 323 - 1234',
        address: ['213 Fake Street', 'San Pedro', 90731]
        }
    };
var list = function(obj){
    for (var key in obj) {
        console.log(key);
    };
};

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


#2

Did you try using the data given in the instructions? The address property is an array of four elements, not three.

The code looks okay save for the semi-colons on for and if. Only the function expressions need a semi-colon since they are assignment statements.

Remember to call the search function with "Steve".


#3

So here's what I have now.

var friends = {
    bill: {
        firstName: 'Bill',
        lastName: 'Nye',
        number: '(213) 213 - 1234',
        address: ['123 Fake Street', 'Los Angeles', 'CA', 90019]
        },
    steve: {
        fistName: 'Steve',
        lastName: 'Irwin',
        number: '(323) 323 - 1234',
        address: ['213 Fake Street', 'San Pedro', 'CA', 90731]
        }
    };
var list = function(obj){
    for (var key in obj) {
        console.log(key);
    };
};

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

But I'm still getting the same error message. Not quite sure what I'm doing wrong.

And currently, the console is showing all the info about Bill, and not Steve.


#4

Looks like it was based on how I set up my properties of friends. Can someone explain to me why it was wrong?

I used the data set in the given example and it worked fine, so it definitely was how I set up the object.


#5

nevermind. I feel really dumb. For Steve, i mispelled firstName... wow.


#6

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