Manipulating Complex Objects bug

Manipulating Complex Objects bug
0.0 0

#1

Tell us what’s happening:

Your code so far

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

Your browser information:

Your Browser User Agent is: Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/64.0.3282.186 Safari/537.36.

Can anybody help me with this challenge
No hints are available and i am stuck on this challenge on freecodecamp
the challenge is based on adding certain keys and their data in a class of array type
in java script pl tell me what i am doing wronge

Link to the challenge:


#2

You are almost there. A few hints:

  • The record you added should be an object. You have only added key-value pairs, not an object. An object looks like this:
{
  key: value,
  key2: value2
}
  • Elements in an array should be separated by a comma (you already did this for the key-value pairs)

#3

:thinking::roll_eyes::smirk::upside_down_face::nerd_face::ear::nose::pray:


#4

Thanks for the help I got it on the form from another gitter with a similar problem as mine


#5

I used push() function to push the given data in the array like this :
// Add record here
]; <<<<<<<<<<( this is the end of the main array of the class )
myMusic.push(
{“artist”: “Devo”,
“title”: “We are Devo”,
“release_year”: 1984,
“formats”: [“CD”, “Cassette”, “LP”]
} );

// is this a correct way to add data i a array type class or their is another way to do it
thanks in advance for your reply :slight_smile:


#6

I guess this works, but the challenge suggests that you add the object inside the array directly (instead of indirectly with .push()).

You could just do:

var myMusic = [
  {
    "artist": "Billy Joel",
    "title": "Piano Man",
    "release_year": 1973,
    "formats": [ 
      "CS", 
      "8T", 
      "LP" ],
    "gold": true,
   
  },
  
  // Add record here
 {
   "artist":"macmellar",
   "title":"superstar",
   "release_year":2018,
   "format":["data1",
             "data2",
             "data3"]
  }
];

Note the comma after the first object and the curly braces (which you initially missed) around the second object.