Hello all. I am in need of some help and understanding of what this problem is asking. I have taken each criteria and evaluated and then put it into what I believe is the right statement.
// Only change code below this line
function updateRecords(id, prop, value) {
//If value is empty (""), delete the given prop property from the album.
if (value === "") {
delete collection[id][prop];
}
//If prop is "tracks" and value isn't empty (""), push the value onto the end of the album's existing tracks array.
else if (prop == "tracks" && value != "") {
collection[id][prop].push(value);
}
//If prop is "tracks" but the album doesn't have a "tracks" property, create an empty array before adding the new value to the album's corresponding property.
else if (prop == "tracks" && collection[id].hasOwnProperty(tracks) == false) {
collection[id][prop] = collection[id][prop][""];
}
else {
collection[id][prop][value] = collection[id][prop][value];
}
return collection;
}
console.log(updateRecords(5439, "tracks", "test"))
The function works for certain things and not others. Of course it doesn’t pass. Here is an error I keep getting:
TypeError: Cannot read property 'push' of undefined
This has been kicking my butt for a week. I had stopped last week and decided to go learn Javascript through other means and then over the last day I have watched the 3 hour video for FCC on Youtube and stopped at this point. I have seen the answer on that video but really want to understand what it is about what I am trying to do here.
Please help me understand each of these if
statements I have made and why they are incorrect.
Thank you!