# Record Problem Java

**URL:** <https://forum.freecodecamp.org/t/record-problem-java/474260>\
**Category:** Curriculum Help\
**Tags:** javascript\
**Created:** [August 17, 2021, 5:01pm UTC](https://forum.freecodecamp.org/t/record-problem-java/474260 "2021-08-17T17:01:12Z")\
**Posts on this page:** 19\
**Page:** 2

<div class="post-metadata">

**Author:** ![JeremyLT](https://sea3.discourse-cdn.com/freecodecamp/user_avatar/forum.freecodecamp.org/jeremylt/32/291894_2.png) [@JeremyLT](https://forum.freecodecamp.org/u/JeremyLT)\
**Post date:** [August 18, 2021, 6:13pm UTC](https://forum.freecodecamp.org/t/record-problem-java/474260/21 "2021-08-18T18:13:52Z")

</div>

> [@lydiapernia](#):
>
> I have to deletes one for when prop is tracks and one for if prop is not tracks.

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

---

<div class="post-metadata">

**Author:** ![lydiapernia](https://sea3.discourse-cdn.com/freecodecamp/user_avatar/forum.freecodecamp.org/lydiapernia/32/138838_2.png) [@lydiapernia](https://forum.freecodecamp.org/u/lydiapernia)\
**Post date:** [August 18, 2021, 6:18pm UTC](https://forum.freecodecamp.org/t/record-problem-java/474260/22 "2021-08-18T18:18:50Z")

</div>

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?

---

<div class="post-metadata">

**Author:** ![JeremyLT](https://sea3.discourse-cdn.com/freecodecamp/user_avatar/forum.freecodecamp.org/jeremylt/32/291894_2.png) [@JeremyLT](https://forum.freecodecamp.org/u/JeremyLT)\
**Post date:** [August 18, 2021, 6:20pm UTC](https://forum.freecodecamp.org/t/record-problem-java/474260/23 "2021-08-18T18:20:45Z")

</div>

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

> [@JeremyLT](#):
>
> ```auto
> } else if (prop === "tracks" && records[id][prop] !== [] && value !== "") {
> records[id][prop] = [value];
> } else if (prop === "tracks" && records[id][prop] === [] && value !== "") {
> records[id][prop].push(value);
> }
> 
> ```

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.

---

<div class="post-metadata">

**Author:** ![lydiapernia](https://sea3.discourse-cdn.com/freecodecamp/user_avatar/forum.freecodecamp.org/lydiapernia/32/138838_2.png) [@lydiapernia](https://forum.freecodecamp.org/u/lydiapernia)\
**Post date:** [August 18, 2021, 6:25pm UTC](https://forum.freecodecamp.org/t/record-problem-java/474260/24 "2021-08-18T18:25:43Z")

</div>

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.

---

<div class="post-metadata">

**Author:** ![JeremyLT](https://sea3.discourse-cdn.com/freecodecamp/user_avatar/forum.freecodecamp.org/jeremylt/32/291894_2.png) [@JeremyLT](https://forum.freecodecamp.org/u/JeremyLT)\
**Post date:** [August 18, 2021, 6:27pm UTC](https://forum.freecodecamp.org/t/record-problem-java/474260/25 "2021-08-18T18:27:19Z")

</div>

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?

---

<div class="post-metadata">

**Author:** ![lydiapernia](https://sea3.discourse-cdn.com/freecodecamp/user_avatar/forum.freecodecamp.org/lydiapernia/32/138838_2.png) [@lydiapernia](https://forum.freecodecamp.org/u/lydiapernia)\
**Post date:** [August 18, 2021, 6:29pm UTC](https://forum.freecodecamp.org/t/record-problem-java/474260/26 "2021-08-18T18:29:08Z")

</div>

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. ):

---

<div class="post-metadata">

**Author:** ![JeremyLT](https://sea3.discourse-cdn.com/freecodecamp/user_avatar/forum.freecodecamp.org/jeremylt/32/291894_2.png) [@JeremyLT](https://forum.freecodecamp.org/u/JeremyLT)\
**Post date:** [August 18, 2021, 6:30pm UTC](https://forum.freecodecamp.org/t/record-problem-java/474260/27 "2021-08-18T18:30:11Z")

</div>

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

So…

> [@JeremyLT](#):
>
> Above you were playing around with `hasOwnProperty` to see if a property is defined. Why did you go away from that?

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.

---

<div class="post-metadata">

**Author:** ![lydiapernia](https://sea3.discourse-cdn.com/freecodecamp/user_avatar/forum.freecodecamp.org/lydiapernia/32/138838_2.png) [@lydiapernia](https://forum.freecodecamp.org/u/lydiapernia)\
**Post date:** [August 18, 2021, 6:39pm UTC](https://forum.freecodecamp.org/t/record-problem-java/474260/28 "2021-08-18T18:39:12Z")

</div>

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.

---

<div class="post-metadata">

**Author:** ![lydiapernia](https://sea3.discourse-cdn.com/freecodecamp/user_avatar/forum.freecodecamp.org/lydiapernia/32/138838_2.png) [@lydiapernia](https://forum.freecodecamp.org/u/lydiapernia)\
**Post date:** [August 18, 2021, 6:51pm UTC](https://forum.freecodecamp.org/t/record-problem-java/474260/29 "2021-08-18T18:51:11Z")

</div>

ok I changed the last if else statements to

```auto
 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.

---

<div class="post-metadata">

**Author:** ![ILM](https://sea3.discourse-cdn.com/freecodecamp/user_avatar/forum.freecodecamp.org/ilm/32/363239_2.png) [@ILM](https://forum.freecodecamp.org/u/ILM)\
**Post date:** [August 18, 2021, 6:54pm UTC](https://forum.freecodecamp.org/t/record-problem-java/474260/30 "2021-08-18T18:54:43Z")

</div>

> [@lydiapernia](#):
>
> `records[id][prop].hasOwnProperty(prop)`

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.

 ![Pre-formatted-text](https://global.discourse-cdn.com/freecodecamp/original/3X/1/b/1b18854f1059217f29370444396145cc3a0cd8ae.gif)

See [this post](https://forum.freecodecamp.org/t/forum-code-formatting/25574) to find the backtick on your keyboard.  
**Note:** Backticks (`) are not single quotes (').

---

<div class="post-metadata">

**Author:** ![lydiapernia](https://sea3.discourse-cdn.com/freecodecamp/user_avatar/forum.freecodecamp.org/lydiapernia/32/138838_2.png) [@lydiapernia](https://forum.freecodecamp.org/u/lydiapernia)\
**Post date:** [August 18, 2021, 6:58pm UTC](https://forum.freecodecamp.org/t/record-problem-java/474260/31 "2021-08-18T18:58:31Z")

</div>

Thank you all for your help it finally passed!

---

<div class="post-metadata">

**Author:** ![lydiapernia](https://sea3.discourse-cdn.com/freecodecamp/user_avatar/forum.freecodecamp.org/lydiapernia/32/138838_2.png) [@lydiapernia](https://forum.freecodecamp.org/u/lydiapernia)\
**Post date:** [August 18, 2021, 7:03pm UTC](https://forum.freecodecamp.org/t/record-problem-java/474260/32 "2021-08-18T19:03:11Z")

</div>

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!

---

<div class="post-metadata">

**Author:** ![JeremyLT](https://sea3.discourse-cdn.com/freecodecamp/user_avatar/forum.freecodecamp.org/jeremylt/32/291894_2.png) [@JeremyLT](https://forum.freecodecamp.org/u/JeremyLT)\
**Post date:** [August 18, 2021, 7:12pm UTC](https://forum.freecodecamp.org/t/record-problem-java/474260/33 "2021-08-18T19:12:18Z")

</div>

> [@lydiapernia](#):
>
> 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)

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

---

<div class="post-metadata">

**Author:** ![lydiapernia](https://sea3.discourse-cdn.com/freecodecamp/user_avatar/forum.freecodecamp.org/lydiapernia/32/138838_2.png) [@lydiapernia](https://forum.freecodecamp.org/u/lydiapernia)\
**Post date:** [August 19, 2021, 4:48pm UTC](https://forum.freecodecamp.org/t/record-problem-java/474260/34 "2021-08-19T16:48:35Z")

</div>

👍 Thanks for your help!

---

<div class="post-metadata">

**Author:** ![lydiapernia](https://sea3.discourse-cdn.com/freecodecamp/user_avatar/forum.freecodecamp.org/lydiapernia/32/138838_2.png) [@lydiapernia](https://forum.freecodecamp.org/u/lydiapernia)\
**Post date:** [August 19, 2021, 4:51pm UTC](https://forum.freecodecamp.org/t/record-problem-java/474260/35 "2021-08-19T16:51:12Z")

</div>

> [@JeremyLT](#):
>
> console.log

I am using console.log to check my work! 😀

---

<div class="post-metadata">

**Author:** ![ILM](https://sea3.discourse-cdn.com/freecodecamp/user_avatar/forum.freecodecamp.org/ilm/32/363239_2.png) [@ILM](https://forum.freecodecamp.org/u/ILM)\
**Post date:** [August 19, 2021, 4:53pm UTC](https://forum.freecodecamp.org/t/record-problem-java/474260/36 "2021-08-19T16:53:50Z")

</div>

what does `console.log` tell you?

---

<div class="post-metadata">

**Author:** ![lydiapernia](https://sea3.discourse-cdn.com/freecodecamp/user_avatar/forum.freecodecamp.org/lydiapernia/32/138838_2.png) [@lydiapernia](https://forum.freecodecamp.org/u/lydiapernia)\
**Post date:** [August 19, 2021, 5:32pm UTC](https://forum.freecodecamp.org/t/record-problem-java/474260/37 "2021-08-19T17:32:32Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![ILM](https://sea3.discourse-cdn.com/freecodecamp/user_avatar/forum.freecodecamp.org/ilm/32/363239_2.png) [@ILM](https://forum.freecodecamp.org/u/ILM)\
**Post date:** [August 19, 2021, 5:36pm UTC](https://forum.freecodecamp.org/t/record-problem-java/474260/38 "2021-08-19T17:36:54Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![system](https://global.discourse-cdn.com/freecodecamp/original/3X/e/1/e1c433102e34b46dfaa3e15d13ab9a514b127078.svg) [@system](https://forum.freecodecamp.org/u/system)\
**Post date:** [February 18, 2022, 5:36am UTC](https://forum.freecodecamp.org/t/record-problem-java/474260/39 "2022-02-18T05:36:58Z")

</div>

Closed on February 18, 2022, 5:36am UTC

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

[Previous page](https://forum.freecodecamp.org/t/record-problem-java/474260.md?page=1)
