7.Search for a friend--output question


#1

Hi, Sorry this isn't formatted but it's too long to screen cap.
I'm just trying to understand why this is printing out extra information after my search function.
Here's my code:
(I'm printing "======" dividers to tell what's doing what in the results, and wrote the output in the comments. My question is in the last line: why does the code return two extra copies of Steve's info and an extra copy of Bill's info? Where in my code is this coming from?)

var friends = new Object();
friends.bill = new Object();
friends.bill.firstName = "Bill";
friends.bill.lastName = "Gates";
friends.bill.number = "555-1999";
friends.bill.address = ['One Microsoft Way', 'Redmond', 'WA', '98052'];

friends.steve = new Object();
friends.steve.firstName = "Steve";
friends.steve.lastName = "Jobs";
friends.steve.number = "555-2007";
friends.steve.address = ['1 Infinite Loop', 'Cupertino', 'CA', '61801']

console.log(friends) //prints bill and steve info
console.log("====================");
console.log(friends.bill) //prints bill info
console.log("====================");
console.log(friends.bill.address) //prints bill's address info
console.log("====================");

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

list(friends) //prints "bill" and "steve" on separate lines

console.log("====================");

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

search("Steve"); //prints steve info

console.log("====================");

search("Bill"); //prints bill info

console.log("====================");

//My code ends here, and I expected the output to end here also. But after this it prints Steve's info, Steve's info again, and then Bill's info. My question is why does it print this extra info??


#2

@nataliedeclerck,

It is the course-checker,
doing its tests.