JavaScriot error: ..... Oops, try again. It looks like your search function doesn't return contact information for Steve


#1

var friends = {};

friends.ola =
{
firstName:"ola" ,
lastName: "ola",
age: 24,
number:"(+353) 123456789",
address:['10 xyz','Dundalk','Louth','IRL']
};
friends.temi =
{
firstName:"temi" ,
lastName: "adams",
age: 14,
number:"(+353) 123006782",
address:['1 wdef','Dublin','Co-Dublin','IRL']
};
friends.bill =
{
firstName:"bill" ,
lastName: "andy",
age: 26,
number:"(+353) 56987456",
address:['11', 'loyef','Dundalk','Louth','IRL']
};
friends.david =
{
firstName:"david" ,
lastName: "davis",
age: 56,
number:"(+353) 123456789",
address:['10 xyz','Dundalk','Louth','IRL']
};
friends.Esther =
{
firstName:"ola",
lastName: "adams",
age: 24,
number:"(+353) 987456321",
address:['48 ghtyr','Brain road','Duleek','IRL']
};
friends.steve =
{
firstName:"steve" ,
lastName: "simon",
age: 35,
number:"(+353) 78956489",
address:['4', 'astehr','Drogheda','Louth','IRL']
};

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

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


#2

Maybe
change the firstName's of "bill" to "Bill" and "steve" to "Steve".
as the course-checker is using the calls

search("Steve");
search("Bill");

and in your search function
change

 console.log(friends[allFriends].number);

into

 console.log(friends[allFriends].number);

#3

OH sorry for the late response. Figured it out. the rtn statement was wrongly placed.

Thankx all the same. ........... cheers !!!

for(var allFriends in friends)
{
if(friends[allFriends].firstName === name)
{
console.log(friends[allFriends].number);
}
return friends[allFriends]; // The rtn was inside the if statement instead of the for loop.
}


#4

@holar,
in the code you presented in your last post
you are forgetting to close the for-loop with its own closing-curly-bracket-}