Error in the Code of the exercise ( I think)

Tell us what’s happening:
Hello everyone , I believe there has been a mistake in the code given to start this exercise, above the “// Only change code below this line” I believe there must be a ( and not a {
so something like that

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

  **Your code so far**

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

User Agent is: Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/92.0.4515.131 Safari/537.36

Challenge: Write Concise Object Literal Declarations Using Object Property Shorthand

Link to the challenge:

No, you write functions like

function example () {
  return 1
}

Not

function example () (
  return 1
)

Latter isn’t valid code


Edit:

Arrow functions allow you to miss off the return and the curly brackets if you’re just returning a single expression, like

const example = () => 1

Rather than

const example = () => {
  return 1
}

But objects are also written using curly brackets, so if you write

const example = () => { foo: 1 }

That’s going to be parsed as

const example = () => {
  return foo: 1
}

So you just put some brackets round it

const example = () => ({ foo: 1 })

And it gets parsed as

const example = () => {
  return { foo: 1 }
}

You aren’t doing that here though, so not applicable

2 Likes

I see, my bad in that case since what i did ( and seemed to pass the test ) was:

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

I assumed it was a typo. thanks for the feedback anyway!

1 Like

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