Test is not running properly (Basic JavaScript: Record Collection)

Test is not running properly (Basic JavaScript: Record Collection)
0.0 0

#1

It’s about this exercise: https://learn.freecodecamp.org/javascript-algorithms-and-data-structures/basic-javascript/record-collection

My function looks like this:

function updateRecords(id, prop, value) {
  if (value != "") {
    if (id in collection) {
      switch (prop) {
        case "album":
          collection[id]["album"] = value;
          break;
        case "artist":
          collection[id]["artist"] = value;
          break;
        case "tracks":
          if ("tracks" in collection[id]) {
            collection[id]["tracks"].push(value);
          } else {
            collection[id]["tracks"] = [value];
          }
      }
    }
  }
  console.log(collection);
  return collection;
}

When I click on “Run the Tests”, it says the following:
// running test
After updateRecords(2548, “artist”, “”), artist should not be set
After updateRecords(2548, “tracks”, “”), tracks should not be set
// tests completed

But as far as I see, the artist or the track isn’t being set, right?
So shouldn’t my solution be good?


#2

The tests are running properly. You function isn’t meeting all the requirements.

If value is empty (""), delete the given prop property from the album.


#3

I’ve edited your post for readability. When you enter a code block into the forum, precede it with a line of three backticks and follow it with a line of three backticks to make easier to read. See this post to find the backtick on your keyboard. The “preformatted text” tool in the editor (</>) will also add backticks around text.