Record Collection - JS - a little help please

Record Collection - JS - a little help please
0

#1

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;
}

#2

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


#3

Great, thank you @ArielLeslie


#4

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


#5

Great, thank you for you help!