Need help with this challenge, Manipulating Complex Objects

Can some one please tell me what i have done wrong and what i can do about this my code… Need Ur help.

Your code so far


var myMusic = [
  {
    "artist": "Billy Joel",
    "title": "Piano Man",
    "release_year": 1973,
    "formats": [ 
      "CD",
      "8T",
      "LP"
    ],
    "gold": true
  }
  // Add record here
 
  var myMusic = [
    {
  "artist": "Smokey",
   "title": "Needles and pains",
   "release_year": 1970,
   "formats": [ 
   "CD",
   "Cassette",
    "LP"],
   "gold": true
    }
    ];

Your browser information:

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

Link to the challenge:
https://learn.freecodecamp.org/javascript-algorithms-and-data-structures/basic-javascript/manipulating-complex-objects

1 Like

Declaring variables inside an array is not a valid syntax.

Remember that you are “inside” a myMusic Array, this means that all you have to do is simply write your new object, correctly formatted inside it.

{
“artist”: “Smokey”,
“title”: “Needles and pains”,
“release_year”: 1970,
“formats”: [
“CD”,
“Cassette”,
“LP”],
“gold”: true
}
];

Not working yet… What should i do?

Hello Karons, the objective of the challenge, was to insert another object in the array.
As you can notice, an array is something like [1,2]; you can see that the numbers are separated by commas. Same happens with objects inside of arrays, [{object},{object}] you can notice that objects are between { }, and there is a comma separating them.

In the first message I saw that you rewrote the myMusic variable; but all you have to do is write another object in the array that was already written. Just dont forget the comma. Please let us know if you solved it! :slight_smile:

Just cannot get it right, just frustrated with this now, can U just give me an example please?

{
[myMusic 1]
“artist”: “Smokey”,
“title”: “Needles and pains”,
“release_year”: 1970,
“formats”: [
“CD”,
“Cassette”,
“LP”],
“gold”: true
}
];

Sure!

var ListOfObjects = [{
name:“pencil”,
color:“blue”
}]

There is one object{} with name and color in the array[] called ListOfObjects; what the challenge is asking you to do, is write inside of the List, and make something like this:

var ListOfObjects = [{
name:“pencil”,
color:“blue”
},
{
name: “book”,
color: “red”
}]

is this not it?
var myMusic = [{

artist:“Smokey”,

title:“Needeles and Pains”

},

{

release_year: “1970”,

formats: [“CD”, “Cassette”,“LP”]

}];

This array contains two objects but you shouldn’t change the existing object and you need to create the new object following instructions

Which existing objects, the one on the challenge?

{
“artist”: “Billy Joel”,
“title”: “Piano Man”,
“release_year”: 1973,
“formats”: [
“CD”,
“8T”,
“LP”
],
“gold”: true
}

This is my code, just not working, not even one is correct yet… Tired…
var myMusic = [

{

artist:“Smokey”,

title:“Needeles and Pains”

},

{

release_year: “1970”,

formats: [“CD”, “Cassette”,“LP”]

}];

Please paste all the code in the editor not just what you added, as it is important that it is correct also in relation to that

I don’t understand U, it’s not helping…

I have asked you to post all the code that is written in the editor so that I can help you more

But, you need to create one object, you have created two. Inside the array myMusic there should be two objects, one is already there, the other you need to create yourself. You need to give it properties following the instructions,
image
So your new object should have 4 properties (you have created two objects with two properties each)

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

{

artist:“Smokey”,

title:“Needeles and Pains”

},

{

release_year: “1970”,

formats: [“CD”, “Cassette”,“LP”]

}];

What should i add and where should i add code…

var myMusic = [

{
artist:“Smokey”,
title:“Needeles and Pains”
},

{
release_year: “1970”,
formats: [“CD”, “Cassette”,“LP”]
}];

You are redeclaring the variable inside the array, you don’t need to do that as explained above
Instead you need to do something like this:

var myMusic = [
   { /* first object that already exist */ },
   { /* second object that you need to create */ }
]

{
artist:“Smokey”,
title:“Needeles and Pains”
},

{
release_year: “1970”,
formats: [“CD”, “Cassette”,“LP”]
}];

OK, What else?

No, in that way the array has three objects, instead including the already existing object the array should have two objects inside so you only need to add one object, not two

var myMusic = [
  {
   /* this is the first object that already exist */
    "artist": "Billy Joel",
    "title": "Piano Man",
    "release_year": 1973,
    "formats": [ 
      "CD",
      "8T",
      "LP"
    ],
    "gold": true
  },
  { /* you need to create a second object here */ }
]
1 Like

{[
“artist”:“Smokey”,
“title”:“Needeles and Pains”
“release_year”: “1970”,
“formats”: [“CD”, “Cassette”,“LP”]
}];