Unable to wrap my head around challenge

Unable to wrap my head around challenge
0

#1

I’m currently stuck on challenge # 210, record collection. Can anyone help me out with this?


#2

What exactly you need the help with?


#3

Sorry for the late response. Well, I keep getting the error: "TypeError: Cannot read property ‘ABBA’ of undefined"
Here’s my function:

function updateRecords(id, prop, value) {
if (collection[id][prop] == “tracks” && collection[id][prop][value] === “”) {
arr.collection[id].tracks.push();
}

if (collection[id][prop] == “tracks” && collection[id][prop][value] !== “”){
arr.collection[id].tracks.push(value);
}

if (collection[id][prop][value] === “”){
delete collection[id][prop];
}

return collection;

}


#4

Assuming test case updateRecords(5439, "artist", "ABBA");

In your first if your check looks like this:

if (collection[5439]["artist"] == "tracks" && ...

But collection doesn’t have "artist" property for id 5439 so you get an error.


From the challenge’s description:

If prop isn’t “tracks” and value isn’t empty (""), update or set the value for that record album’s property.

So you should check
if (prop !== "tracks" && value !== "") {...
and so on…

I wrote a similar post in another thread, but SPOILER ALERT it includes solution: http://forum.freecodecamp.com/t/record-collection-challange/10949/49


#5

Sorry again for the late response, university has me running circles lol
Thank you so very much for the help! That fixed it for me :slight_smile: