JavaScript Algorithms and Data Structures - ES6 - Write Concise Object Literal Declarations Using Object Property Shorthand


I can’t understand why my solution:

const createPerson = (name, age, gender) => ({name, age, gender});

to this task is not accepted.

Although I get the expected result, I get the error Your code should not use key:value. As far as I see it, though, I am not using one… Am I missing something or is this a bug?

why are you using the execution brackets()? is there a reasoning for that? you just need to return an object. how that happens in ES6.
I would do it (x,y,z)=>{ return {x,y,z}}

Isnt that irrelevant? Why you ask that question?

They are used to do implicit return of an object

What is the rest of your code? Just that one line?

Make sure you removed the initial code and didn’t just comment it out. The test will fail if any code in the editor has a : even if it is commented out.


@lasjorg , thanks!!! That was exactly the problem. I had commented out the original code and that is why it was giving an error. I am new to freeCodeCamp, so this knowledge will be useful if it ever happens again. Much appreciated :slight_smile:

Yes, that is my answer to the problem.

Because it throws an error since it thinks that “{” is the opening to the function instead of the object nomenclature.

This topic was automatically closed 182 days after the last reply. New replies are no longer allowed.