JavaScript: Record Collection Test Fail

Edit - challenge link: https://www.freecodecamp.org/learn/javascript-algorithms-and-data-structures/basic-javascript/record-collection

My code doesn’t pass this test:
After updateRecords(5439, "tracks", "Take a Chance on Me") , tracks should have "Take a Chance on Me" as the last element.

Can anyone help me figure out why because this is really frustrating?

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

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

    else {
      delete collection[id][prop];
    }

  return collection;
}
``

A link to the challenge would be much appreciated.

Here’s the link https://www.freecodecamp.org/learn/javascript-algorithms-and-data-structures/basic-javascript/record-collection

It’s a shame your syntax error doesn’t provide a line number in the FCC editor. Running in repl.it, I found that you have the syntax error on line 39.

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

When the property is not tracks, you don’t have an array so you can’t push.

Once you fix this, you’ll see you have a logic error. Your if statements are out of order.

I get it!

Thanks for looking into it.