Comment lines to JavaScript ES6 point 16

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

This is the exercise to do:

const createPerson = (name, age, gender) => {
// Only change code below this line
return {
name: name,
age: age,
gender: gender
};
// Only change code above this line
};

Perhaps the 2 comment lines are a bit misleading, because it is necessary to change also the 2 outer curly brackets, which are just above and below the comments, to turn them into round brackets

You don’t need to, you can keep the explicit return statement and change the object there

Ok, thank you very much!
So this should be the solution keeping the explicit return statement:

const createPerson = (name, age, gender) => {
// Only change code below this line
return { name, age, gender };
// Only change code above this line
};

And the alternative with round brakets:
const createPerson = (name, age, gender) => ( { name, age, gender } );

yes, exactly!

you don’t need to actually change outside of the delined space with this

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