Record Collection Completed. Suggested Improvements?

Hi Guys,

I finished the Record Collection challenge. It took some tweaking and some frustration but I got there in the end. I’m open to all suggestions and possible improvements. There are always more efficient ways!?

// 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": [ 
        "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) {
  //Remove the property if the value is null, else update the properties.
  if (value === "") {
    delete collection[id][prop];
  } else if (prop == "tracks" && value !== "") {
    if (!collection[id].hasOwnProperty(prop)) {
           collection[id][prop] = [];
  } else {
     collection[id][prop] = value;
  return console.log(collection);

// Alter values below to test your code
updateRecords(2468, "tracks", "blue");
1 Like

I doubt it. There may be some clever way to write a terser version of the code, but in the end, you’ll be doing all the same operations. That looks almost exactly like the solution I wrote as well!

1 Like

Just wondering. How long did it take you guys to complete this challenge? What’s your best guess and how much experience prior to FCC have you had with javascript?

Hey tourejord, If i remember correctly it took me a little bit over an hour. I’m definitely a beginner to JavaScript. I did the JavaScript course on CodeCademy before starting FreeCodeCamp. I still struggle a lot at times. I usually try google a lot when a get stuck.

1 Like

@Nims An hour. That’s impressive. I need to take more breaks apparently. Because that lesson took me 10+ hours and I felt like I was reading English for the first time. I had just started CodeCademy’s JavaScript when I found FCC which is probably where the learning curve difference lye’s. Thank you so much for the help though. Your final solution is what finally got me through and helped me to be able to explain to myself what was going on. or so I think.

@tourdejord I forget the exact timings, I’d say it was actually well over an hour :p. I struggle with some of the JavaScript myself. There are some others projects where I get stuck for ages. I’m currently trying to do the Weather App API and I’ve spent all day trying to work out the AJAX and I’m not getting very far! I feel like giving up at times. When I can’t solve problems I get upset and don’t think i’m good enough.

ha, I think we all get there. You are so close to “front end cert” though. Keep on man.

Hahaha, yes I think everyone does. Thanks for the encouragement. Having a community definitely helps. I’m loving the structure to FreeCodeCamp. I still get overwhelmed of what I should be learning next in addition to working through FreeCodeCamp. My priority is learning JavaScript and a UI framework such as React.