Search for a friend; One Bill, Two Steve

<PLEASE USE THE FOLLOWING TEMPLATE TO HELP YOU CREATE A GREAT POST!>

<Below this line, add a link to the EXACT exercise that you are stuck at.>
https://www.codecademy.com/courses/javascript-beginner-en-3bmfN/0/7?curriculum_id=506324b3a7dffd00020bf661#

<In what way does your code behave incorrectly? Include ALL error messages.>
Oops, try again. Did you create a function called search?

```

var friends = {
bill: {
firstName: “Bill”,
lastName: “Cipher”,
number: “(217) 819-2728”,
address: [‘Galaxy St.’,‘Univille’,‘Illuminati, (IL)’,‘1337’]

}, 
steve: {
    firstName: "Steve",
    lastName: "Jobs",
    number: "(696) 969-6969",
    address: ['Place St.','Somewhere City','Whatever, (WE)','9001']
}

};

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

list(friends);

<do not remove the three backticks above>
1 Like

hi the error say…

Oops, try again. Did you create a function called search?

2 Likes

Yeah; that’s what the error says.

1 Like

Now, I’m getting an output of a ton of numbers, ranging from 0 - 4, repeating, many times. Here’s my new code, that I changed, up, a bit:

var friends = {
bill: {
firstName: “Bill”,
lastName: “Cipher”,
number: “(217) 819-2728”,
address: [‘Galaxy St.’,‘Univille’,‘Illuminati, (IL)’,‘1337’]

},

steve: {
firstName: “Steve”,
lastName: “Jobs”,
number: “(696) 969-6969”,
address: [‘Place St.’,‘Somewhere City’,‘Whatever, (WE)’,‘9001’]
}
};

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

list(friends);
console.log(friends);

1 Like

But you didn’t create a search function like the lesson aske you to…

1 Like

This is my output:

bill
steve
{ bill:
{ firstName: ‘Bill’,
lastName: ‘Cipher’,
number: ‘(217) 819-2728’,
address: [ ‘Galaxy St.’, ‘Univille’, ‘Illuminati, (IL)’, ‘1337’ ] },
steve:
{ firstName: ‘Steve’,
lastName: ‘Jobs’,
number: ‘(696) 969-6969’,
address: [ ‘Place St.’, ‘Somewhere City’, ‘Whatever, (WE)’, ‘9001’ ] } }
0
1
2
3
4
0
1
2
3
4
0
1
2
3

1 Like

Oh, I get what you’re saying now; but I still cannot really get it to work. I have no idea what I’ve screwed up, to what extent; now.

1 Like

Here’s my new code, I just can’t figure this out, what-so-ever:
(I think something’s wrong, with the Search function.)

var friends = {
    bill: {
        firstName: "Bill",
        lastName: "Cipher",
        number: "(217) 819-2728",
        address: ['Galaxy St.','Univille','Illuminati, (IL)','1337']
        
    }, 
    steve: {
        firstName: "Steve",
        lastName: "Jobs",
        number: "(696) 969-6969",
        address: ['Place St.','Somewhere City','Whatever, (WE)','9001']
    }
};

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

list(friends);
search(bill);
1 Like

Hi your search function should takes has argument name then inside your if statemnt you should put friends[firstName].firstName equal to name so it should be like that

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

then you should call your search() function with the " " around "Steve".
and you don’t need of an argument inside the call funcion list();
Hope that could help you

1 Like

Now, I’m getting an output of two Steves; here is my code:

var friends = {
    bill: {
        firstName: "Bill",
        lastName: "Cipher",
        number: "(217) 819-2728",
        address: ['Galaxy St.','Univille','Illuminati, (IL)','1337']
        
    }, 
        firstName: "Steve",
        lastName: "Jobs",
        number: "(696) 969-6969",
        address: ['Place St.','Somewhere City','Whatever, (WE)','9001']
    }
};

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(name);
1 Like

H I said…

then you should call your search() function with the " " around “Steve”.

1 Like

Sorry, this has gone on so long; but if you are talking about,

search("Steve");

then, it just makes it worse. I get three Steves

1 Like

But do you still get the error?

1 Like

There are no error messages, either way; but I want to try, and, just get one of each.

2 Likes

first inside you friend you don’t have steve

var friends = {
    bill: {
        firstName: "Bill",
        lastName: "Cipher",
        number: "(217) 819-2728",
        address: ['Galaxy St.','Univille','Illuminati, (IL)','1337']
        
    }, 
        firstName: "Steve",
        lastName: "Jobs",
        number: "(696) 969-6969",
        address: ['Place St.','Somewhere City','Whatever, (WE)','9001']
    }
};

then change the “Steve” with “steve” in the search function

1 Like

First of all, that was a typo;

    steve: {
        firstName: "Steve",
        lastName: "Jobs",
        number: "(696) 969-6969",
        address: ['Place St.','Somewhere City','Whatever, (WE)','9001']
    }
};

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

Second, of all; I tried that already,

search("steve");

Same output.

1 Like

SO you have that as output?

bill
steve
{ firstName: 'Steve',
  lastName: 'Jobs',
  number: '(696) 969-6969',
  address: [ 'Place St.', 'Somewhere City', 'Whatever, (WE)', '9001' ] }
{ firstName: 'Steve',
  lastName: 'Jobs',
  number: '(696) 969-6969',
  address: [ 'Place St.', 'Somewhere City', 'Whatever, (WE)', '9001' ] }
{ firstName: 'Bill',
  lastName: 'Cipher',
  number: '(217) 819-2728',
  address: [ 'Galaxy St.', 'Univille', 'Illuminati, (IL)', '1337' ] }
1 Like

Yes, that is my output; indeed.

Character limit…

1 Like

I really don’t know why it do that…

@epic41262816 I don’t know what happened to my previous post regarding this, but your code might be repeated for this reason.