7 - Output in triplicate, has code


#1

My code is passing the Check but the results come out in triplicate, complete with open curly brackets. Can't figure it out, even after looking through the old questions and tips, using the archived tips and code suggestions. The list output for lesson 6 worked just like it was supposed to, but that's gone for this round, along with the odd output from the search.

this is the output:

{ firstName: 'Steve',
lastName: 'Jobs',
number: '(408) 555-5555',
address: [ '1 Infinite Loop', 'Cupertino', 'CA', '95014' ] }
{ firstName: 'Steve',
lastName: 'Jobs',
number: '(408) 555-5555',
address: [ '1 Infinite Loop', 'Cupertino', 'CA', '95014' ] }
{ firstName: 'Steve',
lastName: 'Jobs',
number: '(408) 555-5555',
address: [ '1 Infinite Loop', 'Cupertino', 'CA', '95014' ] }
{ firstName: 'Bill',
lastName: 'Gates',
number: '(206) 555-5555',
address: [ 'One Microsoft Way', 'Redmond', 'WA', '98052' ] }
{"firstName":"Steve","lastName":"Jobs","number":"(408) 555-5555","address":["1 Infinite Loop","Cupertino","CA","95014"]}

here is my code:

var friends = {

bill: {
    firstName: "Bill",
    lastName: "Gates",
    number: "(206) 555-5555",
    address: ["One Microsoft Way","Redmond","WA", "98052"]
},
steve: {
    firstName: "Steve",
    lastName: "Jobs",
    number: "(408) 555-5555",
    address: ["1 Infinite Loop","Cupertino","CA","95014"]
},
mark: {
    firstName: "Mark",
    lastName: "Zuckerberg",
    number: "(502) 555-5555",
    address: ["1 Hacker Way","Menlo Park", "CA","94025"]
}

};

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

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

search("Steve");

Any help would be greatly appreciated.


#2

@elnarcho,

++++ why second display of last Item
+++++++++++++++++++++++++++++
It is the Javascript interpreter which is running in this course-environment,
it display's the last non-displayed action...

You will also encounter this, when you are doing a return-statement
as last action...
You could counter this by using a
console.log( " " ); as last statement....

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


#3

Yes, I remember that the display will put out whatever is last in the cache, but it doesn't look to be repeating, as it shows the 'bill' object then prints out, in a different format, the 'steve' object's data.

I still don't get why the output is code and not the formatted version (unless I guess that's what's supposed to be output), nor why the initial list of keys (lower case first names from the previous lesson) is now absent. I feel that I'm missing something major on the formatting goal, or in the lesson itself.


#4

@elnarcho,
Could give a display of what you are writing about....??


#5

Imgur
Imgur

This is a screen capture of what the page is displaying.

Thanks for any help!


#6

@elnarcho,

If you would see this....

test_functions":"try {\n search(\"Steve\");\n} catch(ReferenceError) {\n return \"Did you create a function called search?\";\n}\n\nif (typeof(search) !== 'function') {\n return \"It looks like search isn't a function.\";\n}\n\nvar steve_search = search(\"Steve\");\nvar bill_search = search(\"Bill\");\n\nif (!(steve_search instanceof Object)) {\n\treturn \"It looks like your search function doesn't return contact information for Steve.\";\n}\nif (!(bill_search instanceof Object)) {\n\treturn \"It looks like your search function doesn't return contact information for Bill.\";\n}\n\nif (CC.prints().length === 0) {\n\treturn \"It looks like you didn't log anything to the console.\";\n}\n\nif (error) {\n return \"It looks like you have an error in your code! Check the message for more details: \" + error;\n}\n\nreturn true;


#7

I was having exactly the same problem. After speaking to someone at CodeAcademy, it seems the console simulator may be the issue. We tried pasting the same code into CodePen and got the output I was expecting: