Tell us what’s happening:
I recommend modifying the instructions for this lesson inside the code editor. “Only change code above/below this line” teaches learners to use return
and use additional { }
inside of an arrow function where they’re not necessary, which leads to more verbose, and less clean, code. Rather, the lesson should reinforce use of the syntax as shown in the lesson’s example:
const getMousePosition = (x, y) => ({ x, y });
While the return
keyword can be used, it makes for cleaner code as an ES6 arrow function to remove the { }
that are outside of the lines and instead write the solution as:
const createPerson = (name, age, gender) => ({name, age, gender});
After all, when JavaScript encounters this function and returns an output, its not as worried with the line separations as we are for styling and readability, it will simply return a single line output:
{name: 'stringName', age: integer, gender: 'stringGender'}
Your code so far
const createPerson = (name, age, gender) => {
// Only change code below this line
return {
name,
age,
gender,
};
// Only change code above this line
};
Your browser information:
User Agent is: Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:109.0) Gecko/20100101 Firefox/111.0
Challenge: {{challengeTitle}} ES6 - Write Concise Object Literal Declarations Using Object Property Shorthand
Link to the challenge: