7. Search in friend


#1

I really don;t understand whats wrong

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 key in friends) {
console.log(key);
}
};

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


#2

error on that line with the ++

on these two lines if you wish to use the dot notation then there is no need for [] but if you want to use the the square brackets then there is no need for the dot

you have not defined Steve anywhere before use


#3

i just outlined your syntax errors. if the logic of your code is not accepted by the tester then try your best to fix it


#4

this is my code, i get this error message SyntaxError: Unexpected token '['. Expected a property name after '.'.
i don't understand please help!

var friends = {
bill:{
firstName: "Bill",
lastName: "Gates",
number:"01040404",
address: ["silliconvalley road"," ","2","CA"]
},
steve: {
firstName: "Steve",
lastName: "Jobs",
number: "983983924859",
address: ["silliconvalley road"," ","1","CA"]

}
};

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

  var search = function(name) {

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


#5

tromben, it's not friends.[key], it's friends.key OR friends[key]. One or the other. If you try to mix the two it rejects it as an error and won't run.

Your console statement looks like this:

console.log(friends.[key])

when it should look like:

console.log(friends.key) or console.log(friends[key])

just like rydan mentioned above.


#6

Now i get it Thanks!!!