Need help with Record Collection

I get the right output but couldn’t clear this test. However I change my code fourth and fifth conditions fail. Is there any mistake in my code?

Failed conditions:

  1. After updateRecords(1245, “tracks”, “Addicted to Love”), tracks should have “Addicted to Love” as the last element.
  2. After updateRecords(2468, “tracks”, “Free”), tracks should have “1999” as the first element

// Setup
var collection = {
    "2548": {
      "album": "Slippery When Wet",
      "artist": "Bon Jovi",
      "tracks": [ 
        "Let It Rock", 
        "You Give Love a Bad Name" 
      ]
    },
    "2468": {
      "album": "1999",
      "artist": "Prince",
      "tracks": [ 
        "1999", 
        "Little Red Corvette" 
      ]
    },
    "1245": {
      "artist": "Robert Palmer",
      "tracks": []
    },
    "5439": {
      "album": "ABBA Gold"
    },
    add:function add(id,prop,value){
      [].push.call(this[id][prop],value);
    }
};
// Keep a copy of the collection for tests
var collectionCopy = JSON.parse(JSON.stringify(collection));

// Only change code below this line
function updateRecords(id, prop, value) {
  if(collection[id].hasOwnProperty(prop)){
    if(value==""){
       delete collection[id][prop]; 
      //alert("good day sir");
    }else{
      if(prop=="tracks"){
        collection.add(id,prop,value);
      }else{
        collection[id][prop]=value;
      }
    }
  }else{
      if(prop=="tracks"){
        collection[id][prop]=[];
        collection[id][prop].push(value);
      }else{
        collection[id][prop]=value;    
      }
    
  }
  return collection;
}

// Alter values below to test your code
updateRecords(1245, "tracks", "Addicted to Love");


// Setup
var collection = {
    "2548": {
      "album": "Slippery When Wet",
      "artist": "Bon Jovi",
      "tracks": [ 
        "Let It Rock", 
        "You Give Love a Bad Name" 
      ]
    },
    "2468": {
      "album": "1999",
      "artist": "Prince",
      "tracks": [ 
        "1999", 
        "Little Red Corvette" 
      ]
    },
    "1245": {
      "artist": "Robert Palmer",
      "tracks": []
    },
    "5439": {
      "album": "ABBA Gold"
    },
    add:function add(id,prop,value){
      [].push.call(this[id][prop],value);
    }
};
// Keep a copy of the collection for tests
var collectionCopy = JSON.parse(JSON.stringify(collection));

// Only change code below this line
function updateRecords(id, prop, value) {
  if(collection[id].hasOwnProperty(prop)){
    if(value==""){
       delete collection[id][prop]; 
      //alert("good day sir");
    }else{
      if(prop=="tracks"){
        collection.add(id,prop,value);
      }else{
        collection[id][prop]=value;
      }
    }
  }else{
      if(prop=="tracks"){
        collection[id][prop]=[];
        collection[id][prop].push(value);
      }else{
        collection[id][prop]=value;    
      }
    
  }
  return collection;
}

// Alter values below to test your code
updateRecords(1245, "tracks", "Addicted to Love");


I forgot to add the collection. Now help me with this program.

With If block I want to push the element into the tracks array.
Else block just changes the value of the existing property.

The output is right. But still the conditions are not satisfied. Kindly test it once yourself.

I’ve solved it by moving the ‘add’ function 's code to where it is required directly.

function updateRecords(id, prop, value) {
  if(collection[id].hasOwnProperty(prop)){
    if(value==""){
       delete collection[id][prop]; 
    }else{
      if(prop=="tracks"){
        [].push.call(collection[id][prop],value);
      }else{
        collection[id][prop]=value;
      }
    }
  }else{
      if(prop=="tracks"){
        collection[id][prop]=[value];
        
      }else{
        collection[id][prop]=value;    
      }
    
  }
  return collection;
}