Record Collection Does Not Add Track to Empty Array

Hello all!

I have only 1 test that won’t pass!

In the Record Collection challenge, the track key does not get added, nor is the value added to the would-be array: updateRecords(5439, "tracks", "Take a Chance on Me") I also noticed the track value is not pushed on an empty array either (with the existing property). Any guidance would be helpful. Here’s the link to the challenge: https://www.freecodecamp.com/challenges/record-collection

***Also, I feel as though I am struggling a little bit with objects/JSON, especially when accessing properties through variables…I’ve coded on and off since 2014, and this is the furthest I’ve been with programming and beginning to understand objects. Are there any suggestions you have to study this more? I’ve looked into various tutorials, but if you have any specific suggestions or how I can practice more, that would be great…I want to feel a bit more confident before moving on in the lessons.***

// 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 !== "") {
    collection[id][prop] = value;
  } else if (prop == "tracks" && value !== "") {
    collection[id][prop].push(value);
  } else if (value === "") {
    delete collection[id][prop];
  }
  return collection;
}

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

Found out the solution from the suggestion of another camper on Gitter.
I don’t want to give away the answer BUT it does have to do with validating if a property is there or not, if it’s not there, you need to add a property…and if it is there, you can push a value onto it. Looking at my question, it made me realize that sometimes the solutions are in the questions we ask!

1 Like