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
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?
@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!
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.