Record Collection - JS - a little help please

Hello,

I’m struggling with the record collection challenge. Could someone please review my current code to see where I’m going wrong? It’s only the last 2 tests that aren’t passing. Many thanks :slight_smile:

function updateRecords(id, prop, value) {
  
 if(prop !== "tracks" && value !== "") {

  collection[id][prop] = value;
}
  
  else if(prop === "tracks" && collection.hasOwnProperty(prop) === false) {

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

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

I cleaned up your code.
You need to use triple backticks to post code to the forum.
See this post for details.

Great, thank you @ArielLeslie

collection.hasOwnProperty(prop) === false
should be
collection[id].hasOwnProperty(prop) === false

2 Likes

Great, thank you for you help!