freeCodeCamp - Manipulating Complex Objects

var myMusic = [
  {
    "artist": "Billy Joel",
    "title": "Piano Man",
    "release_year": 1973,
    "formats": [ 
      "CS", 
      "8T", 
      "LP" ],
    "gold": true
  }
 // Add record here

];

Hint:add a comma and create a similar object as above. ignore any laxcomma warnings.

2 Likes

Is there a question here?

I’ll assume that you’re confused about what to do.

If you have an array of objects:

var myPets = [              // open array of objects
  {                         // start of first object
    "name" : "Sparky",
    "species" : "dog",
    "food" : [
      "meat",
      "dog food",
      "bones"
    ]
  }                         // end of first object
];                          // end of array of objects

Here is an array of objects with only one object. If you want to add more, you need to separate each object with a comma:

var myPets = [              // open array of objects
  {                         // start of first object
    "name" : "Sparky",
    "species" : "dog",
    "food" : [
      "meat",
      "dog food",
      "bones"
    ]
  },                        // end of first object
  {                         // start of second object
    "name" : "Goldie",
    "species" : "fish",
    "food" : [
      "fish food"
    ]
  }                         // end of second object
];                          // end of array of objects

You could chain on as many objects as you want, adding them to your array of objects.

8 Likes

thanks the , after each objects was the problem I had

2 Likes

I solved this one, but can someone explain to me why the “release year” string is written with an underscore?

"release_year" can be used with dot notation .release_year or bracket notation ["release_year"]

"release year" can only be used with bracket notation ["release year"] because it is not a valid identifier

3 Likes
var myMusic = [
  {
    "artist": "Billy Joel",
    "title": "Piano Man",
    "release_year": 1973,
    "formats": [ 
      "CS", 
      "8T", 
      "LP" ,],
    "gold": true
  
  }  // Add record here
  ];{ 
  "artist": "Cesare Siepi",
   "title": "Operatic Arias For Bass",
   "release_year": 1965,
   "formats": [
     "LP",
     "Mono",
     "RE",],  
   "gold": false

  }
This is not working, what am I doing wrong here?
1 Like
var myMusic = [
  {
    "artist": "Billy Joel",
    "title": "Piano Man",
    "release_year": 1973,
    "formats": [ 
      "CS", 
      "8T", 
      "LP" ],
    "gold": true
  },
    {
    "artist": "Linkin Park",
    "title"**_: "Chester Bennington"_**,
    "release_year": 2017,
    "formats": [
      "We are sorry for you.",
      "We are sorry for your family."
      ]
      }
  // Add record here
];
1 Like

had an error with the “release_year”: 2007, on my code,

didnt work till i changed the year to 1973

var myMusic = [
{
“artist”: “Billy Joel”,
“title”: “Piano Man”,
“release_year”: 1973,
“formats”: [ “CS”, “8T”, “LP” ],
“gold”: true
},
{
“artist”: “Cesare Siepi”,
“title”: “Operatic Arias For Bass”,
“release_year”: 1965,
“formats”: [“LP”, “Mono”, “RE”],
“gold”: false
}
];

I think is can running, Episs2man

Hi @rgmorales11, based on the challenge requirements, we really need to use an underscore because this is a fixed rule. If not, then you will receive a code error:

In my own opinion, I never tried to see the difference between having a space or underscore but for best practice, coders use underscore. See for your self here:

**http://javascript.crockford.com/code.html**

@gadalaavinash please specify your question when creating a topic. It helps everyone stay on the same page, and it increases your chance of getting a great answer.

yeah me too, i forgot the comma