Asking for a challenge explanation

Hello!
I’m currently doing this challenge.
I now understand (with the help of the hint) how to complete the challenge. This is the code I write to pass:

function updateRecords(object, id, prop, value) {
  if(prop !== "tracks" && value !== "") {
    object[id][prop] = value;
  } else if(prop === "tracks" && !object[id].hasOwnProperty("tracks")) {
    object[id][prop] = [value];
  } else if(prop === "tracks" && value !== "") {
    object[id][prop].push(value);
  } else if(value === "") {
    delete object[id][prop];
  }

  return object;
}

But I’ve noticed an issue. When you call the function in such configuration: console.log(updateRecords(collection, 5439, 'tracks', '')); the tracks property isn’t removed from the album, although in the last else if statement the functionality is that the given prop has to be removed when the value passed is an empty string.

Although this solution works to pass the test, the functionality this function was intended to serve isn’t working properly in all cases. Is there a way how to solve the issue?

P. S. I hope this makes sense, but if it doesn’t, — let me know and I’ll try my best to explain it once again so the issue is clear.

the way this challenge is configured is tohat the function shhould always get valid input, in this case the 5439 object does not have a tracks property so this is what is executed:

an easy way to solve this would be to change the logic structure and write

function updateRecords(object, id, prop, value) {
  if (value === "") {
    // logic for when the valus is empty string
  } else {
    // logic for when the value is not an empty string
  }
  return object;
}