Record Collection -

Tell us what’s happening:
I tested all and they seem to work . I can’t figure out why I keep getting the auto tests wrong and not being able to pass.

Your code so far


// 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) {

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

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

    return collection[id];
}



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

Your browser information:

User Agent is: Mozilla/5.0 (Macintosh; Intel Mac OS X 10_13_3) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/69.0.3497.100 Safari/537.36.

Link to the challenge:
https://learn.freecodecamp.org/javascript-algorithms-and-data-structures/basic-javascript/record-collection

What do the failing tests say?

Read the instructions carefully:

Your function must always return the entire collection object.

Thank you! I changed the return statement to return collection;, however, I still get errors, where locally tests pass

Looks like you’re not correctly handling the case where the last parameter is an empty string.

But it looks correct here… (thank you so much for helping!)

Again, read the instructions carefully.

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

Thank you!! For a reason that I don’t understand delete collection[id][prop]; worked but delete collection[id].prop; did not.

It’s not the first time I see the bracket notation working and the dot notation failing. Is there a place where I can read more?

It all worked now:)

Rembember that dot notation and bracket notation are different things and they work differently. You can go back to the challenges that introduced them in FCC. (Hint: if you do a search here in the forum, you can include @arielleslie to the search term and find several places where I have gone into detail about this.)

Yes, I remember. I think I didn’t understand completely before, otherwise, I could have saved us a lot of time:) Awesome! Thank yoU!