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.