Record Collection -

Record Collection -
0

#1

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


#2

What do the failing tests say?


#3

Read the instructions carefully:

Your function must always return the entire collection object.


#4

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


#5

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


#6

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


#7

Again, read the instructions carefully.

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


#8

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:)


#9

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.)


#10

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