Bug in exercise for ES6: Write Concise Object Literal Declarations Using Object Property Shorthand

For this exercise, if you follow the instruction of “Only change code below/above this line”, your code won’t work. You have to change the first and last curly braces to parentheses to succeed.

The execise:

Use object property shorthand with object literals to create and return an object with name , age and gender properties.

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

  // Only change code below this line

  return {

    name: name,

    age: age,

    gender: gender

  };

  // Only change code above this line

};

My solution:

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

you can still make it work using explicit return, instead if converting the function to implicit return

it is only the object tha needs changed, not anything else

just this part needs to be changed

1 Like