Search for a freind


#1
}

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

it keeps on saying sytaxError missing } after function body HELP


#2

Hi can you post all your code ? because this part of the code it's fine


#3

sure
var friends = new Object();
friends.bill = {
firstName: "Bill",
lastName: "Gates",
number: "505, 505, 5050",
address: ['microsoft', 'xbox drive']
};
friends.steve = {
firstName: "Steve",
lastName: "Jobs",
number: "606, 606, 6060",
address: ['apple', 'iPhone drive']
};
var list = function(freinds) {
for(var firstName in freinds) {
console.log(firstName)
}
var search = function(name) {
for(var key in friends) {
if(friends[key].firstName === name) {
console.log(friends[key])
return friends[key]
}
}
};
search("Steve");


#4

this part you didn't close the function list }

var list = function(freinds) {
    for(var firstName in freinds) {
       console.log(firstName)
    }
}<== add one here

#5

i just found it
:slight_smile:


#6

var friends = {};
friends.bill = {
firstName: "Bill",
lastName: "Gates",
number: "505, 505, 5050",
address: ['microsoft', 'xbox drive']
};
friends.steve = {
firstName: "Steve",
lastName: "Jobs",
number: "606, 606, 6060",
address: ['apple', 'iPhone drive']
};
var list = function(freinds) {
for (var firstName in freinds) {
console.log(firstName);
}
};
var search = function(name) {
for (var key in friends) {
if (friends[key].firstName === name) {
console.log(friends[key]);
return friends[key];
}
}
};
list(friends);
search("Steve");


#7

@ovjeet

friends array doesn't exist. Maybe you're looking for friends?