7.search for a friend, it work but


#1

Hello! This is my code and it worked but it is console.log repeated five times, any suggestions why this happens and how to improve it?.
var friends = {
bill : {
firstName : "bill",
lastName: "gates",
number : "111 222 333",
address : ["One Microsoft Way", "Redmond","WA", "98052"]
},
// Justo aqui arriba es la coma para separarlos.
steve : {
firstName : "steve",
lastName : "jobs",
number : "444 555 666",
address : ["1 Infinite Loop", "Cupertino", "CA","95014"]
}
};
var list = function(friends) {
for (firstName in friends) {
console.log(firstName);
}
};

var search = function (steve) {
for (var steve in friends) {
if (firstName === "steve") {
console.log(friends.steve );
return friends.steve;
} else {
console.log (" entry not found");
}
}
};
search();

// and here is what is logged.

{ firstName: 'steve',
lastName: 'jobs',
number: '444 555 666',
address: [ '1 Infinite Loop', 'Cupertino', 'CA', '95014' ] }
{ firstName: 'steve',
lastName: 'jobs',
number: '444 555 666',
address: [ '1 Infinite Loop', 'Cupertino', 'CA', '95014' ] }
{ firstName: 'steve',
lastName: 'jobs',
number: '444 555 666',
address: [ '1 Infinite Loop', 'Cupertino', 'CA', '95014' ] }
{ firstName: 'steve',
lastName: 'jobs',
number: '444 555 666',
address: [ '1 Infinite Loop', 'Cupertino', 'CA', '95014' ] }
{"firstName":"steve","lastName":"jobs","number":"444 555 666","address":["1 Infinite Loop","Cupertino","CA","95014"]}


#2

This exercise is very weird.

Half of the logs are yours, and then half are Codecademy's Code-Checker.

I would say just ignore it. :slightly_smiling:


#3

@jamona,
Remove

from your search function
AND

In some sections of this course, the course-checker Display's data
this you could then identify by placing two EXTRA code-line's at the END of your code:
console.log( "== My End ==" );
console.log( "== All that is displayed now, is the course-checker ==" );


#4

@leonhard.wettengmx.n, this is a great idea to help distinguish between the two! :slightly_smiling:


#5

Good idea leonhard, it is so obvious and simple that it never occurred to me :D.
And cadecodes, what do you mean with " the exercise is very weird", do you mean my own coding or the exercise itself?, any way i can improve my code?.
Thanks for the fast reply!.