Javascript - manipulating complex objects

I am having trouble with this assignment. It asks me to put in another album after the billy joel one, but do I add a break or something to signal that I have another album? Here’s my code. Idk I’ve been having a hard time with Javascript so I don’t think I’m explaining my problem well.

You need to copy and paste your code into your post for us to see. The link you posted is just a link to the problem that only you can see your solution when logged in.

Also, please type three backticks ( ` ) on the line immediately before and after the code you paste in, so that it stays in the same format (indentations, etc…) and make it easier for us to read it.

whoops sorry

var myMusic = [
  {
    "artist": "Billy Joel", 
    "title": "Piano Man",
    "release_year": 1973,
    "formats": [ 
      "CS", 
      "8T", 
      "LP" ],
    "gold": true
    
    
  
 
     "artist": "Lorde",
     "title" : "Pure Heroine",
     "release_year": 2014,
     "formats": [
       "mp3",
       "LP",
       "radio"],
     "gold": true
   }
    
  
  
  
];

Your code is private to your browser and your account - we cannot see it - you will need to paste it here or in some code sharing site

This exercise is practice with objects - an object is collection of arbitrary things - each thing has a name - the javascript term is property - and a value i.e. the thing itself

arbitrary means each thing can be a number a string an object an array etc - anything

an object is marked by a pair of braces {...} - you put the things inside the braces following the property: value syntax

this differentiates an object from an array which is a collection of things between brackets [...] - an array is an indexed or ordered collection of things - since an array is ordered each thing in an array gets its index or position number as its name - so in bracket [...] notation there is no need to write the name/index of each thing separately since the order is visible - so only the thing/value itself needs to be written separated from other things with a comma

in this exercise myMusic is an array of album things - each album is an object so each album needs a separate pair of braces {...}

here is my code :

var myMusic = [
  {
    "artist": "Billy Joel", 
    "title": "Piano Man",
    "release_year": 1973,
    "formats": [ 
      "CS", 
      "8T", 
      "LP" ],
    "gold": true
    
    
  
 
     "artist": "Lorde",
     "title" : "Pure Heroine",
     "release_year": 2014,
     "formats": [
       "mp3",
       "LP",
       "radio"],
     "gold": true
   }
    
  
  
  
];

Remember that myMusic is just an array of objects. The problem starts with 2 objects inside the array and the instructions want you to add another one in the middle.

The problem starts with:

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

OK, now to answer your question. Arrays have elements which are separated by commas. Below is an example of an array of 4 objects. The objects are empty, but it will allow you to see the format and separators needed for a valid array of objects. Hopefully, this will help you see what you need to do now in the current challenge.

var myArrayOfEmptyObjects = [ { }, { }, { }, { } ];
2 Likes

You miss:
objectName = {
before:

so if you want to accomplish this lesson your code should look like that:

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

  myMusic1 = {“
    artist”: “Artysta”,
    “title”: “Cos tam”,
    “release_year”: 1999,
    “formats”: [“mp3”, “wml”, “vlm”]
  }

];

Good luck :wink:

I’ve edited your post for readability. When you enter a code block into the forum, remember to precede it with a line of three backticks and follow it with a line of three backticks to make easier to read. See this post to find the backtick on your keyboard.

markdown_Forums