Record Collection - Seeking Advice/Feedback

I’ve been stuck at this for two weeks, now. I struggle, and hit the wall, I go back and review the earlier lessons, but there seems to be a rather large gap between the difficulty on this particular challenge and everything prior to it. I don’t feel I was entirely prepared for this, to be honest.

Here’s my code. I am sure there’s a lot I am missing here.

function updateRecords(object, id, prop, value) {

 if (prop !== "tracks" && value !== "") {

    return object[id][prop] == value; 

 }

  else if (prop == "tracks" && id.hasOwnProperty(tracks) ) {

   return object[id][prop].push([value]);

 }

 else if (prop == "tracks" && value !== "") {

   return object[id][prop].push([value]);

 }

 else if (value == "") {

   delete object[id][prop];

 }

}

Any feedback on what I am missing is appreciated. Thank you.

This is making a big problem for you. You want to update the object and then return the updated object.

id is a string
hasOwnProperty works only on objects
tracks written like that is an undefined variable - maybe you wanted the string "tracks"?

if the object does not have the tracks property, you can’t push to
an array that doesn’t exist

the requirement is to always return the whole object, all your return statements are something different, or in case of value == "" you just do not have a return statement

Thank you for the response,

I do not quite understand why tracks must be a string or else it is undefined – it is not a string in the instructions?

I think the nature of tracks is where I am getting confused, since I am unsure if it is a variable I need to define, or a property – I was under the impression it was a property, since the instructions, since that is what the instructions seem to imply:

, a prop (like artist or tracks )

if the object does not have the tracks property, you can’t push to
an array that doesn’t exist

Right, that makes sense. Do you know of a lesson I can refer back to on creating empty arrays?

As far as value ==“” , I put that for values that are empty strings.

Hopefully, everything I am saying here is understandable.

Thanks again for taking the time to provide feedback.

you create an empty array with []

it is an object property, but if you use bracket notation you need to pass in the property name as is, if you put it in without quotes, it doesn’t stay and it gets evaluated as a variable, so you end trying to access the property undefined, if you use a string, it is exactly the property name being accessed as a string is just the final result

you still need to return a value

you need to return the whole object in all cases, in the case of value == "" there is not a return statement, in all the other cases you are not returning the whole object

1 Like

This topic was automatically closed 182 days after the last reply. New replies are no longer allowed.