Record Collection: I pass the tests, not the module

Hi there,
I wrote my code, could pass the cases given when clicking submit, yet my answer is still not accepted. I worked quite on this record collection, but now I have no clue left. And the reply doesn’t give any detail of what sort ever.
Could someone please help me with the bug or some explanation about how this can be possible? Thks :blush:

function updateRecords(object, id, prop, value) {

 
  if (prop == "tracks" && collection[id].hasOwnProperty("prop") == 1 && value != 0)

  {

    //console.log("if number 1"); ///////////////////////

    collection[id][prop].push(value);

  }

  if (prop == "tracks" && collection[id].hasOwnProperty("prop") == 0 && value != 0){

      //console.log("if number 2"); /////////////////////////////////

      collection[id]["tracks"] = [value];

  } if (value == ""){

    //console.log("if number 3"); /////////////////////////////////

      if (prop == "artist"){

          delete collection[id]["artist"];

          } 

            else if (prop == "tracks"){

            delete collection[id]["tracks"];

          } else if (prop == "albumTitle"){

            delete collection[id]["albumTitle"];

          }

    

  } if (prop != "tracks" && value != ""){

    //console.log("if number 4"); /////////////////////////////////

    collection[id][prop] = value;}

 

 console.log(object);

  return object;

}
1 Like

you are operating on one object, and then returning a different object

to make the function reusable, you can’t use the global object collection but will need to always use the function parameter object

1 Like

Thank you so much @ilenia, it worked! I felt stuck and you saved my day! :grinning: