.7 search for a friend - could use a little help


#1

Hello,
I keep getting this error
Oops, try again. It looks like your search function doesn't return contact information for Steve.
and I can't seem to get it to work.

here is my code:

var friends = {};
friends.bill = {
    firstName: 'bill',
    lastName: 'lib',
    number: '(123) 456-7890',
    address: ['123 four street','las vegas','NV']
};
friends.steve = {
    firstName: 'steve',
    lastName: 'eve',
    number: '(555) 555-5555',
    address: ['555 five road','las vegas','NV']
};
var list = function(object){
    for(var key in object){
        console.log(key);
    }
}
list(friends);

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

#2

Hi this line

console.log(search('steve'));

try to change "steve" with "Steve"


#3

@wizmarco hey man just tried it and got the same results. but my resutls are just this now:

    bill
    steve
    undefined

before they look like this:

    bill
    steve
    { firstName: 'steve',
      lastName: 'eve',
      number: '(555) 555-5555',
      address: [ '555 five road', 'las vegas', 'NV' ] }
    { firstName: 'steve',
      lastName: 'eve',
      number: '(555) 555-5555',
      address: [ '555 five road', 'las vegas', 'NV' ] }

#4

after doing that

try to change "steve" with "Steve"

to the call function then in your object

friends.bill = {
    firstName: 'bill',
    lastName: 'lib',
    number: '(123) 456-7890',
    address: ['123 four street','las vegas','NV']
};
friends.steve = {
    firstName: 'steve',
    lastName: 'eve',
    number: '(555) 555-5555',
    address: ['555 five road','las vegas','NV']
};

change the firstName of both steve and billl to "Steve" and "Bill" like that

friends.bill = {
    firstName: 'Bill',
     ....
};
friends.steve = {
    firstName: 'Steve',
    ...
};

#5

@wizmarco oh my gosh. thanks. that was driving me crazy, I could not figure it out. :+1:


#6

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