Telling me fix this fix that won't help because I dont understand a single thing


#1

I have the same code as he does, but can you explain, it looks like I just cant do this one, its just too hard.
Can you give me the code, because telling me fix this fix that won't help because I dont understand a single thing in this 'Search for a friend' exercise.
Thanks in advance!


7. search for a friend
#2

There's nothing too hard if you keep trying :sweat_smile:, post your code and we can solve it together.


#3

var friends = {
bill: {
firstName: "Bill",
lastName: "Gates",
number: "(206) 555-5555",
address: ['One Microsoft Way', 'Redmond', 'WA', '98052']
}
};

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

Alright, that's my code, I'd appreciate if you helped me


#4

First off here,

Your function should take a differnet parameter for example,

var search = function(name) {

And here you just put this in the wrong order,

should be,

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

Lastly your console.log,

should only check for the variable key like,

console.log(friends[key]);

And with an else statement your bracket notation might still be off but without you would only need three brackets like so,

}
}
};


#5

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