Search for Friend Returning All


#1

Unable to figure this out. Read over it multiple times and cant see the difference between mine and the example yet each time it returns all contacts.

Code:
var friends={};
friends.bill = {
firstName: "Bill",
lastName: "Gates",
number: "(206) 555-5555",
address: ['One Microsoft Way','Redmond','WA','98052']};
friends.steve = {
firstName: "Steve",
lastName: "Jobs",
number: "(206) 555-5555",
address: ['One Microsoft Way','Redmond','WA','98052']};
friends.ted = {
firstName: "Ted",
lastName: "Jones",
number: "(206) 555-5555",
address: ['One Microsoft Way','Redmond','WA','98052']};

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

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

search("Steve");

Console:
{ firstName: 'Steve',
lastName: 'Jobs',
number: '(206) 555-5555',
address: [ 'One Microsoft Way', 'Redmond', 'WA', '98052' ] }
{ firstName: 'Steve',
lastName: 'Jobs',
number: '(206) 555-5555',
address: [ 'One Microsoft Way', 'Redmond', 'WA', '98052' ] }
{ firstName: 'Steve',
lastName: 'Jobs',
number: '(206) 555-5555',
address: [ 'One Microsoft Way', 'Redmond', 'WA', '98052' ] }
{ firstName: 'Bill',
lastName: 'Gates',
number: '(206) 555-5555',
address: [ 'One Microsoft Way', 'Redmond', 'WA', '98052' ] }
{"firstName":"Steve","lastName":"Jobs","number":"(206) 555-5555","address":["One Microsoft Way","Redmond","WA","98052"]}


#2

Perhaps its a bug with the course or using chrome or something. It still says i completed the lesson successfully when submitting the code so i decided to continue past this for now. I noticed on the next screen (Victory!) where you resubmit the code again to complete the lesson that it ran fine and only returns the search (even if i copy and paste the code from the previous lesson). Still would like to know why this happened if anyone knows, held me up for awhile just because i didn't click past it and ignore that.