Hi,
I had the same problem with the answer. they seem to skip the step:
“If prop is “tracks” but the album doesn’t have a “tracks” property, create an empty array before adding the new value to the album’s corresponding property.”
Below is my code, maybe this will be making more sense for you
function updateRecords(id, prop, value) {
// If prop isn't "tracks" and value isn't empty (""),
if (prop != "tracks" && value != ""){
// update or set the value for that record album's property.
collection[id][prop] = value;
}
// If prop is "tracks" but the album doesn't have a "tracks" property
if (prop == "tracks" && !collection[id].hasOwnProperty(prop)) {
// create an empty array before adding the new value to the album's corresponding property.
collection[id][prop] = [];
}
// If prop is "tracks" and value isn't empty (""),
if (prop == "tracks" && value != "") {
// push the value onto the end of the album's existing tracks array.
collection[id][prop].push(value);
}
// If value is empty (""),
if (value == "") {
// delete the given prop property from the album.
delete collection[id][prop];
} return collection;
};