Problem with Javascript Exercice: "Record Collection"

Tell us what’s happening:

Hi,

I’m having somme difficulties with some “if” conditions in this exercices. Also I’m not sure how I should create an empty arry and update it accordingly.

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) {
  
  if (prop = "tracks" & value!= "") {

    // push the value onto the end of the album's existing tracks array.
    collection[id].push(value);
  }

  if (prop != "tracks" & value !="") {

    // update or set the value for that record album's property.
    collection[id].push(prop[value]);

  }
  if (prop="tracks" & collection.tracks=null) {
    //create an empty array before adding the new value to the album's corresponding property.

    // I DON'T KNOW HOW TO DO! 
  }

  if (value="") {
        // delete the given prop property from the album.
    collection[id].prop="";
  }
  return collection;
}

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

Your browser information:

User Agent is: Mozilla/5.0 (Windows NT 6.1; Win64; x64; rv:52.0) Gecko/20100101 Firefox/52.0.

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

To create a new empty array for the tracks property just assign [] to the property:
collection[id].tracks = []

To delete a property from an object, here says that you need to use the delete operator:

There isn’t any method in an Object itself to delete its own properties (e.g. like Map.prototype.delete()). To do so one has to use the delete operator.

Also in this thread are good advice about this excercise: Help! Record Collection - #10 by gunhoo93

1 Like