Record Problem Java

Did you try it? Copy that line and run it.

yes, but you delete using prop so it is not necessary to check if prop is "tracks" or not
you just delete when value is an empty string

True but I kept trying different things until it worked. I can make the code more concise but for now I want to pass this challenge and where I’m stuck is the tracks array can you explain how I can fix that?

In order to fix it, you have to understand it.

Can you explain, in words, what you are trying to do here? I think that you are close, but your tests in the if are not quite right.

OK I will try. The problem seems to be that when the original collection does not have a tracks array I can’t assign the value to the prop.
so in words if the property is tracks and there is an existing array push the item to the end.
If there isn’t a array assign the the value as a string .
I can take tat out and i will still get the same error message.

Ok, so you have the right idea, but your execution is wrong.

Above you were playing around with hasOwnProperty to see if a property is defined. Why did you go away from that?

Jeremy,
I am new at Javascript and very new on the forum. I’m learning to navigate it as I use it. So I will make mistakes. ):

Sure, you will make mistakes. Everyone makes mistakes. I’m trying to help you fix the mistakes in your code.

So…

Please, work with me here. Why did you go away from hasOwnProperty? That’s a better approach than comparing against === [], but I want to help you get hasOwnProperty working correctly.

Thank you for helping me with the code and with navigating the forum. I really appreciate it. I’m going to redo it with hasOwnProperty and show you.

ok I changed the last if else statements to

 if ( prop === "tracks" &&  records[id][prop].hasOwnProperty(prop) )
 {records[id][prop]= [value];}

 else

{records[id][prop].push(value);}

  return records;

And i still get the same error message.

ok, now let’s take a look at what you are doing here
what is records[id][prop]? is that the object that can have the tracks property?


I’ve edited your post for readability. When you enter a code block into a forum post, please precede it with a separate line of three backticks and follow it with a separate line of three backticks to make it easier to read.

You can also use the “preformatted text” tool in the editor (</>) to add backticks around text.

See this post to find the backtick on your keyboard.
Note: Backticks (`) are not single quotes (').

Thank you all for your help it finally passed!

Jeremy thank you for your help! It finally passed. My mistake was that when I was typing records[id][prop].hasOwnProperty and I should not have included [prop] since that is what I was checking just records[id].hasownproperty(prop) . Is this the correct explanation?? Anyway thank you very much it finally passed!

Bingo. You want to know if records[id] has the property, not if records[id][prop] has the property.

:+1: Thanks for your help!

I am using console.log to check my work! :grinning:

what does console.log tell you?

I’m using it to check the results before I submit the work.

use it also inside your function to check the value of everything