Finally Completed the JS Record Collection Challenge!

Finally Completed the JS Record Collection Challenge!
0

I finally completed this challenge that I’ve been working for hours:https://www.freecodecamp.org/learn/javascript-algorithms-and-data-structures/basic-javascript/record-collection

Here’s my code

function updateRecords(id, prop, value) {
if (prop == "artist" || prop =="album")
{
  if(value !== "")
  {
  collection[id][prop] = value;
  }
  else 
  {
    delete collection[id][prop];
  }

}
else if(prop =="tracks" && value ==""){
  delete collection[id][prop];
}
else if (prop =="tracks" && collection[id][prop])
{
  collection[id][prop].push(value);
}

  else if(prop =="tracks" && collection[id][prop] === undefined)
  {
    collection[id][prop]=[];
  collection[id][prop].push;
  }
    
return collection;

}

It’s not the most elegant code in the world, but I’m ecstatic because this is easily the most challenging task I’ve completed in JS so far.

Hi @Hyperweb ,

That’s AWESOME! I remember this one giving me all kinds of trouble also :slight_smile:

Great job on this, and you will find that working with objects and arrays gets easier over time; it’s also very important for when you are working with JSON data.

https://www.w3schools.com/js/js_json_intro.asp

Good luck and happy coding!