This is a follow-up from a previous thread (here: https://forum.freecodecamp.org/t/basic-javascript-record-collection-in-non-tech-terms-please/224744/9). Apologies if we are not supposed to start new threads but my question has changed slightly since my last post and I figured it would be OK to start a new thread.
This was the last code I tried:
function updateRecords(id, prop, value) {
if (value !== “”){
if (prop === “tracks”){
if (collection.hasOwnProperty[prop] === true){
collection[id][prop].push(value);
}else{
collection[id][prop] = [value];
}
}else{
collection[id][prop] = value;
}
}else{
delete collection[id][prop];
}return collection;
}
But still this testcase was failing: After updateRecords(2468, “tracks”, “Free”), tracks should have “1999” as the first element.
So then I subbed in the code from Basic Code Solution:
if(collection[id][prop])
instead of
if (collection.hasOwnProperty[prop] === true){
I get why the FCC solution worked but I don’t understand why my code was not acceptable?
Thanks!