Javascript - Record Collection Exercise

Hello!

I can’t find what is wrong with the code.

Errors:

  • After updateRecords(2548, “artist”, “”), artist should not be set

  • After updateRecords(2548, “tracks”, “”), tracks should not be set

Code:

function updateRecords(id, prop, value) {

if (prop !== “tracks” && value !== null) {
collection[id][prop] = value;
}

else if (prop === “tracks” && !(collection[id].tracks)) {
collection[id][prop] = [value];
}

else if (prop === “tracks” && value !== null) {
collection[id][prop].push(value);
}

else if (value === null) {
delete collection[id][prop];
}

return collection;
}

Try using “” instead of null :slight_smile: