Record Collection, Why my code doesn't passed?

Hi, i’m currently on challenge 211 : Record Collection Challenge.

After updateRecords(2468, “tracks”, “Free”), tracks should have “1999” as the first element.
This is the only condition that i failed.

i confused because i managed to fulfill the condition and still failed.
collection =
{
“1245”: {
“artist”: “Robert Palmer”,
“tracks”: []
},
“2468”: {
“album”: “1999”,
“artist”: “Prince”,
“tracks”: [
“1999”,
“Little Red Corvette”
]
},
“2548”: {
“album”: “Slippery When Wet”,
“artist”: “Bon Jovi”,
“tracks”: [
“Let It Rock”,
“You Give Love a Bad Name”
]
},
“5439”: {
“album”: “ABBA Gold”,
“artist”: “ABBA”
}
}

And this is my code:
function updateRecords(id, prop, value) {
if(value === “”){

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

Anyone can help me with this?

thank you really appreaciate it

Which object are you calling hasOwnProperty with?

2 Likes

Hi @kevcomedia!!

Thank you, your question made me realize that i forgot to put the id on that line!! really appreaciate it.

I’m using hasOwnProperty to test if the object i called has a “tracks” key. But your question make me realize that i only called an object without specified any key.

silly me. It’s been 2 days i’m stuck with this challenge