freeCodeCamp - Manipulating Complex Objects

freeCodeCamp - Manipulating Complex Objects
0.0 0

#1
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

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.


#3

thanks the , after each objects was the problem I had


#4

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


#5

"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


#6
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?

#7

The lines below:

} // Add record here
];{ 

should be:

} // Add record here
,{ 

Also, you need to add a closing bracket ] after the very last line of code which contains the closing squiggly bracket. myMusic is an array represented between the two square brackets [ ] which contains objects which are represented between the squiggly brackets { }, and the comma between the objects separates the objects in the array.


#8
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
];

#9

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

didnt work till i changed the year to 1973


#10

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


#11

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**


#12

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


#13

yeah me too, i forgot the comma