JSON Record Collection - Little ISSUE

Hello, I’m learning JavaScript and I have an issue with my code.
Topic of the challenge : Link Here
My function :

function updateRecords(id, prop, value) {

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


    return collection;
}

When I check the solution, i have just one unchecked test. Exactly this one :

After updateRecords(2548, "artist", ""), artist should not be set

CONSOLE OUTPUT :

// running test
After updateRecords(2548, "artist", ""), artist should not be set
// tests completed

I CAN’T FIND THE PROBLEM, when i do a console.log in my browser I get all the things normal.
THANKS

Your error message means that

  "artist": "Bon Jovi"

should be set to an empty string.

"artist": ""

1 Like

You should reread the problem and organize what you should do.

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

Is this what the problem is asking for? When do you delete an entry?

1 Like

I figured out my error, and this is the right function

function updateRecords(id, prop, value) {

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


    return collection;
}

the problem was in the last else/if statement.
It has to be

else if (value === "") {
        delete collection[id][prop];
    }

instead of

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

THANKS FOR YOUR HELP !