Search Friends List


#1

I've gotten lost once I got to the search. Here's what i have so far. I'm getting a syntax Error: expected expression, got '}' --Thanks

var friends = {
bill: {
firstName: "Bill",
lastName: "Gates",
number: "707-555-8565",
address: ['One Marcus Way', 'Johnsonville', 'CA', '58648']
},

steve: {
firstName: "Steve",
lastName: "Jobs",
number: "856-485-1468",
address: ['Two Jones Street', 'New York', 'NY', '58597']
}
};

var list = function (input){

for(var firstName in friends){
console.log(firstName);
}};

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


#2

@newb2coding,

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

#3

var friends = {
bill: {
firstName: "Bill",
lastName: "Gates",
number: "123-123-1234",
address: ['1234 doodle way']
},
steve: {
firstName: "Steve",
lastName: "Bee",
number: "321-123-1234",
address: ['4321 doodle way']
}
};

var list = function (friends) {
for (var x in friends) {
console.log(x);
}
};

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


#4

What's wrong with this code, for 7? Because, the left, demonstrates nothing, and, I don't understand, a thing it wants me, to do. (The code's a bit, split up.)

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

list(friends);


#5

@epic41262816,

+++ friends list and search and for-in explained.
Look here for an explanation
object
function
for-in-loop
list-function
search-function
http://www.codecademy.com/forum_questions/545275fd8c1ccc8e3e000a23#comment-5457b12c9c4e9d87cb00003f


#6

var friends = {};
friends.bill = {
firstName: 'bill',
lastName: 'bill',
number: 28,
address: ['mola','makati']
};
friends.steve = {
firstName: 'steve',
lastName: 'st',
number: 28,
address: ['mola','makati']
};

var list = function(cont){
for (var par in friends){
console.log(par);
}
}

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

list(friends);
search("steve");