Write Concise Object Literal Declarations Using Simple Fields

Write Concise Object Literal Declarations Using Simple Fields
0

#1

Tell us what’s happening:
I made changes in the code. But I was not able to pass the test. What do I need to fix or is there an error in the code?

Your code so far


const createPerson = (name, age, gender) => ({
  
  // change code below this line
  
    name: name,
    age: age,
    gender: 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 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/67.0.3396.87 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


#2

const createPerson = (name, age, gender) => ({name, age, gender});
console.log(createPerson(“Zodiac Hasbro”, 56, “male”)); // returns a proper object


#3

Your code has been blurred out to avoid spoiling a full working solution for other campers who may not yet want to see a complete solution. In the future, if you post a full passing solution to a challenge and have questions about it, please surround it with [spoiler] and [/spoiler] tags on the line above and below your solution code.

Thank you.


#4

This challenge is quite confusing because the answer below:

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

requires the modification of the code above and below the prompts in the challenge itself (// change code below this line, // change code above this line).


#5

If the parameter name and the property name are one in the same you don’t have to write them twice like age: age, just age, will suffice


#6

The solution does not require modifications outside the comments.


#7

This is the original challenge format as it appears to me on website:

const createPerson = (name, age, gender) => {
  "use strict";
  // change code below this line
  return {
    name: name,
    age: age,
    gender: gender
  };
  // change code above this line
};
console.log(createPerson("Zodiac Hasbro", 56, "male")); // returns a proper object

I just want to confirm that it’s the same for everybody else. The previous code for HuseyinTurkmenoglu10d has it that the code includes parentheses enclosing the brackets and it does not have the “use strict” statement that my version does. Resetting the code also returns it to the format I posted. I think this is where my confusion is coming from.


#8

I’ve edited your post for readability. When you enter a code block into the forum, precede it with a line of three backticks and follow it with a line of three backticks to make easier to read. See this post to find the backtick on your keyboard. The “preformatted text” tool in the editor (</>) will also add backticks around text.


#9

Thanks. Got it. Has anyone still experienced a difference in versions with regards to the challenge format?