My code returns all the correct values for all of the tests in "Record Collection" challenge, but the tests fail

This is my code:

// Setup
var collection = {
    "2548": {
      "album": "Slippery When Wet",
      "artist": "Bon Jovi",
      "tracks": [ 
        "Let It Rock", 
        "You Give Love a Bad Name" 
      ]
    },
    "2468": {
      "album": "1999",
      "artist": "Prince",
      "tracks": [ 
        "1999", 
        "Little Red Corvette" 
      ]
    },
    "1245": {
      "artist": "Robert Palmer",
      "tracks": [ ]
    },
    "5439": {
      "album": "ABBA Gold",
    }
};
// Keep a copy of the collection for tests
var collectionCopy = JSON.parse(JSON.stringify(collection));

// Only change code below this line
function updateRecords(id, prop, value) {
  return !value ?
    delete collection[id][prop]:
    prop !== "tracks" ?
      collection[id][prop] = value:
      !collection[id][prop] ?
        collection[id][prop] = [value]:
        collection[id][prop].push(value);
}

// Alter values below to test your code
updateRecords(5439, "artist", "ABBA");

And in the test terminal, I’ve run every test function there is, and they all return the correct collection, but the tests still fail. I’m having trouble understanding where I went wrong?

Here’s a link to the challenge if you want to test my code: https://www.freecodecamp.org/challenges/record-collection

From the challenge description: “Your function must always return the entire collection object.”

It does return the whole thing

If I run every test at once, this is what gets returned:

collection = {
   "1245": {
     "artist": "Robert Palmer",
     "tracks": [ 
       "Addicted to Love"
      ]
    },
    "2468": {
      "album": "1999",
      "artist": "Prince",
      "tracks": [ 
        "1999", 
        "Little Red Corvette",
        "Free"
      ]
    },
    "2548": {
      "album": "Slippery When Wet"
    },

    "5439": {
      "album": "ABBA Gold",
      "artist": "ABBA",
      "tracks": [
        "Take a Chance on Me"
      ]
    }
}

Because of the way you put your nested ternaries inside a return statement, it does not always return the whole collection. If you run just the test that is failing and look at what value is returned by the function, you will see that it is only returning "ABBA".

Why is it that the freecodecamp tester returns

image

when I run that same test in the grader, but only returns “ABBA” when run in the browser dev tools? Is something broken with the grader? That makes it kinda hard to test

Also, I’m looking through this and I can’t figure out a way to return the collection manually after making the changes with my statements? What am I missing?

Nevermind, I figured it out. I took the return statement off of the first line and returned the collection afterwards. This gave me an error “Expected an assignment or function call and instead saw an expression” which I’d tried before but never actually submitted because I figured it can’t be right if the console is showing an error, but then I hit run tests, and it worked. There is definitely something weird going on with the grader on this one.

I think that @cdhippen is referring to the tests. It isn’t the test suite that is giving the warning “Expected an assignment or function call and instead saw an expression”. If I had to hazard a guess it’s that the unusual use of ternaries confused the linter.