Contact List Search for Friends


#1

Guys, am I missing something here?

var friends = {

bill: {
firstName: "Bill",
lastName: "Gates",
number: "12345",
address: ['One Microsoft Way','Converse','TX']
},
steve: {
firstName: "Steve",
lastName: "Jobs",
number: "89101112",
address: ['Twenty Two','The Drive','Eastbourne']
}
};
var list = function (friends) {
for (var key in friends) {
console.log (anything);
}
};

var search = function(name) {
    for (var key in friends)  {
        if (friends[key].firstName === "bill") {
            console.log(friends[key);
            return friends['firstName','lastName','number','address'];
        }
        else {
            if (friends[prop].firstName === "steve") {
                console.log(friends[key]);
                return friends['firstName','lastName','number','address'];
            }
        }
};

search("steve");

returns - Oops, try again. There was a problem with your syntax.


#2

Its prints:....

SyntaxError: Unexpected token )


#3

I have found my error with )

It now prints

SyntaxError: Unexpected end of input


#4

can you post the latest version of your code?


#5

var friends = {

bill: {
firstName: "Bill",
lastName: "Gates",
number: "12345",
address: ['One Microsoft Way','Converse','TX']
},
    steve: {
    firstName: "Steve",
    lastName: "Jobs",
    number: "89101112",
    address: ['Twenty Two','The Drive','Eastbourne']
}
};
var list = function (friends) {
        for (var key in friends) {
            console.log (anything);
        }
    };

    var search = function(name) {
        for (var key in friends)  {
            if (friends[key].firstName === "bill") {
                console.log(friends[key]);
                return friends['firstName','lastName','number','address'];
            }
            else {
                if (friends[prop].firstName === "steve") {
                    console.log(friends[key]);
                    return friends['firstName','lastName','number','address'];
                }
            }
    };
search("steve");

#6

name, your function parameter will hold the name you pass into the function when searching:

var search = function(name){
  console.log(name);
}
search("steve");

so you can simply check if friends[key].firstName is equal to name, if so, log friends[key] to the console (you do this) on the line below return friends[key]


#7

Hi,

Sorry, I am still a little lost - do I need to change the words [key] and [name]?


#8

Do I need to be placing a word in place of what I have capitalized?

var search = function (name) {
for (var KEY in friends) {
if (friends[KEY].firstName === "bill") {
console.log(friends[KEY]);
return friends['firstName','lastName','number','address'];
}
else {
if (friends[KEY].firstName === "steve") {
console.log(friends[KEY]);
return friends['firstName','lastName','number','address'];
}
}
};
search("bill");

returns - SyntaxError: Unexpected end of input


#9

Sorted it. Thanks:slight_smile::camel:


#10