Record Collection JSON in JS

Tell us what’s happening:
I can’t able to understand the problem statements clearly.
Can anybody help me, how to approach the problem.

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 (X11; Ubuntu; Linux x86_64; rv:68.0) Gecko/20100101 Firefox/68.0.

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

Based on your question, you are having a problem understanding what you are supposed to do for this challenge. This one is a bit confusing to look at at first, but I’ll try to break it down for you.

You are given a big collection of musical information. Each entry in the collection has a property called id such as "1245" or "2468". These ids have an object as the value, containing information such as artist, album, or tracks.

The function you are writing is supposed to find an object in the collection and update a specific field (prop). It is going to take 3 parameters: id, prop (property), and value. You want to find the object in the collection with that id. This is the object you will be modifying. You will be modifying the prop that is passed with the value that is passed.

So, if we wanted to do updateRecords(5439, "artist", "ABBA"), then we need to find the object 5439 and set the artist to ABBA, then return the whole collection. The end result would look like this:

{
    "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": {
      "artist": "ABBA",
      "album": "ABBA Gold"
    }
}
1 Like