Hi there, I’m working on the ‘Record Collection’ problem and am a bit stuck
https://learn.freecodecamp.org/javascript-algorithms-and-data-structures/basic-javascript/record-collection
I’m currently getting the following errors:
// running test
After updateRecords(2468, "tracks", "Free"), tracks should have "1999" as the first element.
After updateRecords(2548, "tracks", ""), tracks should not be set
This is my code so far. It seems to be working as expected locally, but when I transfer the code to FCC, the tests mentioned above fail. I suspect that it’s my ordering of the conditional statements that is causing the failing tests.
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][prop] = value;
} else if (prop === 'tracks' && !collection.hasOwnProperty('tracks')) {
let tracksArray = [];
tracksArray.push(value);
collection[id][prop] = tracksArray;
} else if (prop === 'tracks' && value) {
collection[id][prop].push(value);
} else if (!value) {
delete collection[id][prop];
}
return collection;
}
Please let me know your thoughts! I’m just looking for a bump in the right direction and not the actual solution. Many thanks!