Search for a friend; One Bill, Two Steve


#1



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


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);


#2

hi the error say...

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


#3

Yeah; that's what the error says.


#4

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);


#5

But you didn't create a search function like the lesson aske you to..


#8

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


#9

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.


#10

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);

#11

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


#14

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);

#15

H I said..

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


#16

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


#17

But do you still get the error?


#18

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


#20

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


#21

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.


#22

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' ] }

#23

Yes, that is my output; indeed.

Character limit...


#24

I really don't know why it do that..


#25

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


Contact List Returning Multiple Keys From The Two Names Even Though the Program Only Instructs for One