Help with record collection code

I have been working on this for two days and still cant figure it out. What am I missing? Here is my code:

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

first thing to do, you will need to use the object parameter, instead of collection


I’ve edited your post for readability. When you enter a code block into a forum post, please precede it with a separate line of three backticks and follow it with a separate line of three backticks to make it easier to read.

You can also use the “preformatted text” tool in the editor (</>) to add backticks around text.

See this post to find the backtick on your keyboard.
Note: Backticks (`) are not single quotes (’).

2 Likes

It helped. Thank you.