Possible typo in ES6 challenge "Concise Object Literal Declarations"

Hello,
There may be a typo in challenge " ES6: Write Concise Object Literal Declarations…" at this URL.

The challenge asks to follow this pattern:

const getMousePosition = (x, y) => ({ x, y });

But within the proposed solution one is supposed to not touch the ending curly brace:

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

  // Only change code below this line
  return {
    name: name,
    age: age,
    gender: gender
  };
  // Only change code above this line
};

arrow functions allow both implicit and explicit return; the pattern to follow is how to write the object, the arrow function should have already been introduced

also you are not following the pattern to create the object

Doesn’t this solution violate the constraints set in the template? (i.e. "only change code above the line)

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

yes, but there you have written the object correctly, in the code above the object is not being written using the feature being taught here (concise object literals)

My apologies @ilenia but I don’t understand how this is normal.
So far in the course I could follow all constraints, including those outlined within templates. Instead to complete this challenge I had to violate a constraint outlined in the template.
I am under the impression that the template of this challenge ought to be modified in the website itself. Isn’t that the case?

It is not the case. You do not need to change the template to pass the challenge.

You can pass this challenge using a one-line arrow function, but you can also pass this challenge using a multi-line arrow function.

This challenge has examples of one and multi-line arrow functions:

@JeremyLT thanks. I have a hard time combining the request in the challenge body to "use object property shorthand with object literals " and the one in the challenge template to maintain the outer curly braces. This solution gets validated but seems a but awkward. Is it the indended one?

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

I think you’re missing a simpler solution. You don’t need to wrap the one line solution like that. You can just directly use the multi-line arrow function syntax.

const createPerson = (name, age, gender) => {
  // Only change code below this line
  return { // We need 'return' in multi-line arrow fns
    name: name, // But we don't want to use this 'prop: value' syntax
    age: age,
    gender: gender,
  };
  // Only change code above this line
};
const createPerson = (name, age, gender) => {
  // Only change code below this line
  return {
    name, // So we can just delete the 'prop:' part since the variables have the right names
    age,
    gender,
  };
  // Only change code above this line
};

or more compactly

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

@JeremyLT I see thanks, my mistake: I thought the round parentesys in the example were mandatory syntactic sugar. Instead they were just meant to pass the object as a single return value from what would otherwise be interpreted as the function body.

Apologies for disturbing you guys, I initially thought I was just reporting a typo. Thanks for your time and patience, you helped me consolidate many things. I will make a donation to the site to make up for the trouble (done).

Hi, welcome to the forum! Just finished the next module you will go through (Debugging). I remember that challenge, honestly, I don’t see what you’re seeing. It’s pretty straight forward this one. But that’s normal, “what’s going on?” is a question that pops up a lot haha
Also I trust these guys from FCC.
But you’re doing great when it comes to questioning what you don’t understand. Anyway, happy coding!

1 Like

Its no trouble at all - we’re here to help

As you learn more high level features of JavaScript, you’ll see more and more places where the same logic can be expressed with different syntax. The template code is written with one solution in mind, but sometimes the syntax that comes to mind for you is different. That’s 100% ok. The first goal with code is correctness. Once the code is correct you edit for style, efficiency, maintainability, etc.

1 Like

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