Basic Javascript - Record collection; why is this not passing?

Have read through this many times and cannot see why this is not passing all tests. The 2nd, 4th, 5th & 6th tests all fail. Can anyone enlighten me as to what I’m doing wrong?

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

It helps for you to provide the link to the challenge… Thanks.

Sorry, of course, here’s the original challenge task, ‘Basic Javascript - Record Collection’; https://www.freecodecamp.org/learn/javascript-algorithms-and-data-structures/basic-javascript/record-collection

I’ll admit, this one took me a few minutes to catch the error. One reason is that the console pane below the FCC editor is not showing you the error. If you open up your browser’s dev tools and look at the console tab while you run the tests you’ll see the error. Also, if you were using a good code editor with a linter you would probably have caught this right away.

Ahha! Jeepers that was hard to find.

1 Like

OMG, I didn’t find that even after almost an hour of re-writing and reading it! :roll_eyes::gun:. Thank you very much @bbsmooth & @JeremyLT for pointing that out.

If you want to save yourself the time writing that, you could throw it into a variable at the top of the function:

function updateRecords(records, id, prop, value) {
  const record = records[id]; // no more having to write [id], whoo!

Thanks Colin, well suggested, refactored like this now :+1:t2:

This topic was automatically closed 182 days after the last reply. New replies are no longer allowed.