Bug in "Manipulating Complex Objects"? (Help me understand)

I’ve been stuck on “Manipulating Complex Objects” for awhile, but when I changed the provided code, it went through?

Here’s the original:

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

Note the right bracket and semicolon after the “// Add record here”.

I kept getting errors about identifiers, and couldn’t get my code to pass until I moved the right bracket and semicolon up, above my code, like this:

var myMusic = [
  {
    "artist": "Billy Joel",
    "title": "Piano Man",
    "release_year": 1973,
    "formats": [ 
      "CS", 
      "8T", 
      "LP" ],
    "gold": true
  }
];// Add record here
  myMusic.push(
    {"artist": "Devo", "title": "We are Devo", "release_year": 1984, "formats": ["CD", "Cassette", "LP"]}
  );

I’m so used to not touching code until where it’s indicated I should that I didn’t touch the right bracket and semicolon until I finally started trying everything.

Were the right bracket and semicolon in the wrong place? Or was there a different way to do this with them where they started?

Thanks for your help!

8 Likes

Ah! I see it now. I had tried the record add before trying the push, but kept getting an error. But now I see that I missed the comma between the two curlies (which you have in your code.

Thank you so much for your help figuring this out :smile:

10 Likes

Thanks for clarifying this, I too was trying to push(), I keep forgetting how “Manual” the lessons are.
CHEERS!
Neb.

2 Likes

I was so stuck on this but thanks guys … your inputs helped alot

3 Likes

It’s a bug in the FCC code:
The comma between the curly braces is missing in the FCC code above the “//add record here”–so it’s a problem w/ the FCC code and NOT LynneDixon’s oversight. (I was having the same problem–and thought there should be a comma between the two objects, but like LD didn’t want to change the code in the “sacred” section. But once I did, it worked like P1xt said.)

10 Likes

tnx for this it help me a lot.

1 Like

Just spent an hour doing different revisions of the same code, read this post 3 times and still did not realize the missing comma after the first set of curly brackets. Its because we are so used to the example code being prepared for us. I guess this is the part in the lessons where they stop spoon feeding us. I agree with @Ailokin I would have never thought I needed to add something too the “sacred” FCC code. :smile:

3 Likes

Great! The comma was messing with my head

3 Likes

I tried your code but is kept show me errors.
then I tried myMusic.push() ; Finally I passed it.

1 Like

ok they should really put that comma in coz it says add record here so you assume everything above is ok, it’s like debugging the exercise…

3 Likes

what coma are you guys talking about i c cant find it

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

1 Like

var myMusic is an array containing objects. Like all arrays, each item in the array is separated by a comma. So in this example the ; immediately before // Add record here in your code snippet should instead be a , because it separates the two objects in the array.

Edit
You also don’t need that penultimate ; either…

5 Likes

Right above “//Add record here”: in the original code snippet, there’s nothing after the curly brace. However, if you read the “Note” (which I’m not sure was in the problem when I did it) in the instruction section, you’ll see that it says that objects need to be separated by a comma. So, like @JacksonBates said, you need a comma not a semi-colon between the curly braces.

3 Likes

what the freak thank you gyus

1 Like

The Comma

wow that one comma did it all…smh! I kept making several attempts until I found this forum still left me a bit confused but I found it thanks to you guys! :grin: Here is my brief explanation of where the comma goes, hope this helps others…

This was my code:

var myMusic = [ { "artist": "Billy Joel", "title": "Piano Man", "release_year": 1973, "formats": [ "CS", "8T", "LP" ], "gold": true
}; <---------------- This Semicolon should be a comma, like this -------------> },

// Add record here

{
"artist": "Pharrell", "title": "Happy", "release_year": 2015, "formats": [ "mp3", "cd" "tape"
]
}
];

Happy Coding Campers :smiley:

5 Likes

I’m sorry but I find it ridiculous as I’ve not come across any exercise where you are expected to assume their code to be potentially incorrect or where you needed to change the code outside of where it’s indicated.

5 Likes

I guess we can consider it some extra, early, experience in debugging :stuck_out_tongue:

3 Likes

Actually there is a trick (sort of) in this problem. The comment line says Add your record now (it does not say Change code below this line) which is a clue that the curly bracket above needs a comma (it does not have one because right now it does not need one). I added the comma and here is my code:

var myMusic = [
{
“artist”: “Billy Joel”,
“title”: “Piano Man”,
“release_year”: 1973,
“formats”: [
“CS”,
“8T”,
“LP” ],
“gold”: true
},
// Add record here
{
“artist”: “me”,
“title”: “mine”,
“release_year”: 1982,
“formats”: [
“cd”,
“lp”,
“dvd”
],
“gold”: true
}
];

6 Likes

OMG. that damn comma, almost put me in aCOMMA -_-

If it wasn’t for the forums, so many people would be left bald from pulling their hairs out trying to solve these.

Sometimes the instructions are a bit lacking…

5 Likes

Yup, the comma for me too.

1 Like