Record Collection help

Tell us what’s happening:

Hey guys, I have read this multiple times and I keep getting lost. On all the sites listed to click on as a refresher are not working. Can someone help break this down with me? I feel so confused.

Your code so far


// Setup
var collection = {
    "2548": {
      "album": "Slippery When Wet",
      "artist": "Bon Jovi",
      "tracks": [ 
        "Let It Rock", 
        "You Give Love a Bad Name" 
      ]
    },
    "2468": {
      "album": "1999",
      "artist": "Prince",
      "tracks": [ 
        "1999", 
        "Little Red Corvette" 
      ]
    },
    "1245": {
      "artist": "Robert Palmer",
      "tracks": [ ]
    },
    "5439": {
      "album": "ABBA Gold"
    }
};
// Keep a copy of the collection for tests
var collectionCopy = JSON.parse(JSON.stringify(collection));

// Only change code below this line
function updateRecords(id, prop, value) {
  
  
  return collection;
}

// Alter values below to test your code
updateRecords(5439, "artist", "ABBA");

Your browser information:

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

Link to the challenge:
https://learn.freecodecamp.org/javascript-algorithms-and-data-structures/basic-javascript/record-collection/

The updateRecords function updates that particular record according to the parameters passed in.

So updateRecords(5439, "artist", "ABBA") means "take record 5439 and change “artist” to “ABBA”.

"5439": {
  "album": "ABBA Gold"
}

// Becomes

"5439": {
  "artist": "ABBA",
  "album": "ABBA Gold"
 }

Hopefully that gets you started in the right direction

@Hjones1387

Hey buddy!

I too was lost with how the problem is laid out particularly with this line:

If prop isn’t “tracks” and value isn’t empty (""), update or set the value for that record album’s property.

at first I thought this line should only update the “album” property of the record i.e. “album”: “Slippery When Wet”" so I will try to break this line for you the best that I can by giving you a hints:

remember there are the 3 arguments: id(example: 5439), prop(“artist”, “album”, “tracks”) and value.

going back to this line: update or set the value for that record album’s property.

record album meant collection [id]
record album’s property meant [prop](artist, album, track)

remember you can update an object’s properties just like you would update a variable so to update an object’s property you just have to change it’s value like so:

collection[id][prop] = value;

as a reference try reviewing “Updating Object Properties” again:
https://learn.freecodecamp.org/javascript-algorithms-and-data-structures/basic-javascript/updating-object-properties/

once you’ve overcome this hurdle it should be smooth sailing for you for the rest of this challenge.

another hint: after this line you may have to check Testing Objects for Properties too.

I hope this helps.

1 Like

Hi buddy i tried this and it works very well

function remove(){
  delete collection[1245]['artist'];
}

this is to to delete example artist field in record 1245
so if you run remove(); it deletes john palmer only from ur record.
however if u want to add a new record to an object to an object
then this

function updateRecords(id, prop, value) {
  return collection[id]={'album':prop,
'val':value};

  
}

I switched up the vars but u get the idea just change it so it matches correct field.
But if you run it again it overwrites probably.
But it creates anyways an object in your object list with an id of id and the object with
artist and albums if u want an array for albums just make an array
like this`


`function updateRecords(id, prop, value) {
  return collection[id]={'album':prop,
'val':value,'array':[2011,2013]};

  
}``

I hope this was helpful.