Help with 7.Search for a friend


#1

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

bill

steve
darius
{ firstName: 'Bill',
lastName: 'Doe',
number: '9068919071',
address: [ 'YCK Road', 'Castle Green', '481' ] }
{ firstName: 'Steve',
lastName: 'Teddy',
number: '906145471',
address: [ 'AMK Road', 'Calrose', '875' ] }
{ firstName: 'Steve',
lastName: 'Teddy',
number: '906145471',
address: [ 'AMK Road', 'Calrose', '875' ] }
{ firstName: 'Bill',
lastName: 'Doe',
number: '9068919071',
address: [ 'YCK Road', 'Castle Green', '481' ] }

This is the results i got, but i can't seem to find the error


Replace this line with your code. 

var friends=new Object();
    friends.bill={
        firstName:"Bill",
        lastName:"Doe",
        number:"9068919071",
        address:["YCK Road","Castle Green","481"]
        };
    friends.steve={
        firstName:"Steve",
        lastName:"Teddy",
        number:"906145471",
        address:["AMK Road","Calrose","875"]
        };
    friends.darius={
        firstName:"Darius",
        lastName:"John",
        number:"903449071",
        address:["MP Road","Tell","853"]
        };
    
    var list  =function(prop){
        for(var contact in prop){
            console.log(contact)
        }
    };
var search = function(name)
{
    for(var key in friends)
    {
        if(friends[key].firstName===name)
        {
            console.log(friends[key]);
        
        }
    }
};
  list(friends);
  search("Bill");


#2

var list  =function(prop){
        for(var contact in prop){
            console.log(contact); // missed ;
        }
    };

but it's not solution. please, post your error message.

EDIT. I check your code in browser console. Results:

bill
steve
darius
Object {firstName: "Bill", lastName: "Doe", number: "9068919071", address: Array[3]}

So, looks like your code is correct. But if you get error message, post it.


#3

Oops, try again.
It looks like your search function doesn't return contact information for Steve.

That's the error message even after i added the semi-colon.

I added return friends[key];
and there is no error message.

I pasted the code from the first page of Contact list course to this page, and I've got the same error.
However,when I pasted my code to the first page, it works without the Bill steve steve Bill repeats.

Perhaps its a technical error?
UPDATED:
I pasted my code to the last page of Contact list Course, and it works without the bill steve steve bill. So I think it might be a technical error.


#4

I tried to pass this lesson using your code and I passed. Try refresh tab or reset code.


#5

This is my old code that I used and it works just fine. Find something in it useful if you can.

var friends = {};
friends["bill"] = {
    firstName : "Bill",
    lastName: "Gates",
    number: "555-555",
    address: []
};


friends.steve = {
    firstName: "Steve",
    lastName: "Spencer",
    number: "555-666",
    address: []
};

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

#6

This is result I have, using code same as you. For me it doesn't look ok, what's wrong?

{ firstName: 'Steve',
lastName: 'Jobs',
number: '987654321',
address: [ 'Elm Street', '34', 'Los Angeles' ] }
{ firstName: 'Steve',
lastName: 'Jobs',
number: '987654321',
address: [ 'Elm Street', '34', 'Los Angeles' ] }
{ firstName: 'Bill',
lastName: 'Gates',
number: '23456789',
address: [ 'Tree Street', '12', 'New York' ] }


#7

I don't know what exactly is your problem because I don't see error from output. Post error message that assignment gave to you if there is one. My code I gave above works perfectly fine.


#8

If I understood question correctly, you posted result from editor and you don't know is that correct. I think, it's correct. By the way, did you call function search() ?


#9

yep, I didn't call function at the end :slight_smile:


#10

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