Question 7 (searching for names)


#1

This is my function I messed up in line 20. Can someone tell me where I went wrong and please explain.
Thanks in advance :slightly_smiling:

var friends = new Object;
friends.bill = new Object();
friends.bill.firstName = "Bill"
friends.bill.lastName = "Gates"
friends.bill.address =['Mushin', 'to', 'mohits']
friends.bill.number = "(692)458945"
friends.steve = new Object();
friends.steve.firstName = "Steve"
friends.steve.lastName = "Gates"
friends.steve.number = ['silicon' + 'valley', "California"]
friends.steve.number = "3578575501"

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

var search = function(name){
for (var names in friends){
if(name === friends.names.firstName){
console.log(friends.names);
return friends.names;
}
else{
console.log("This Name Does not exsist")
}
}

};


#2

We cannot use dot notation when using a variable. Use subscript notation on the variable:

for (var key in friends) {
    if (name === friends[key].firstName) {

    }
}