Tell us what’s happening:
whats wrong with this code
Your code so far
const createPerson = (name, age, gender) =>
"use strict";
// change code below this line
( {
name,
age,
gender
});
// change code above this line
console.log(createPerson("Zodiac Hasbro", 56, "male")); // returns a proper object
Your browser information:
User Agent is: Mozilla/5.0 (Windows NT 6.1; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/76.0.3809.100 Safari/537.36
.
Link to the challenge:
https://learn.freecodecamp.org/javascript-algorithms-and-data-structures/es6/write-concise-object-literal-declarations-using-simple-fields
You’re not returning anything, you need toreturn
a value.
You also left out the brackets ({ }) of the function body. You can only do that when the function contains just one line of code. Since you have the "use strict"
line as well as the line returning the object, you must use brackets and the return statement.
See the https://learn.freecodecamp.org/javascript-algorithms-and-data-structures/es6/use-arrow-functions-to-write-concise-anonymous-functions/ challenge where it says you can leave out the brackets and the retrun statement when the function only contains a return statement (and nothing else).
1 Like
I think its fine since it uses arrow notation of a function
You can elide the return if the entirety of the function body is a single expression. In this case there is a statement and an expression: "use strict";
and the object you want to return – tthe body has two lines of code, you cannot leave out the return
or the curly brackets.