# 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:** 20\
**Page:** 1

<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 17, 2021, 5:01pm UTC](https://forum.freecodecamp.org/t/record-problem-java/474260/1 "2021-08-17T17:01:12Z")

</div>

I am working on RECORD COLLECTION Java problem.

```
   **Your code so far**

```

```auto
       if (prop !=="tracks" && value !== "" ){records[id][prop]= value;} 
 else if (prop !=="tracks" && value === "" ){delete records[id][prop]}
 else if (prop ==="tracks" && value === "" ){delete records[id][prop]}
else if (prop === "tracks" && records[id].hasOwnProperty("prop")) {records[id][prop].push(value);}
else if (prop === "tracks" && value !==""){records[id][prop]= [value];}

```

The message I get  
// running tests After

```auto
updateRecords(recordCollection, 2468, "tracks", "Free")

```

,

```auto
tracks

```

should have the string

```auto
1999

```

as the first element. // tests completed

```auto
// Setup
var recordCollection = {
 2548: {
   albumTitle: 'Slippery When Wet',
   artist: 'Bon Jovi',
   tracks: ['Let It Rock', 'You Give Love a Bad Name']
 },
 2468: {
   albumTitle: '1999',
   artist: 'Prince',
   tracks: ['1999', 'Little Red Corvette']
 },
 1245: {
   artist: 'Robert Palmer',
   tracks: []
 },
 5439: {
   albumTitle: 'ABBA Gold'
 }
};

// Only change code below this line

function updateRecords(records, id, prop, value) {
 if (prop !=="tracks" && value !== "" ){records[id][prop]= value;} 
else if (prop !=="tracks" && value === "" ){delete records[id][prop]}
else if (prop ==="tracks" && value === "" ){delete records[id][prop]}
else if (prop === "tracks" && records[id].hasOwnProperty("prop")) {records[id][prop].push(value);}
else if (prop === "tracks" && value !==""){records[id][prop]= [value];}

 return records;
}

updateRecords(recordCollection, 5439, 'artist', 'ABBA');

```

```
   **Your browser information:**

```

User Agent is: `Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/92.0.4515.131 Safari/537.36 Edg/92.0.902.73`

**Challenge:** Record Collection

**Link to the challenge:**

> **[freeCodeCamp.org](https://www.freecodecamp.org/learn/javascript-algorithms-and-data-structures/basic-javascript/record-collection)**
>
> Learn to Code — For Free

---

<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 17, 2021, 5:02pm UTC](https://forum.freecodecamp.org/t/record-problem-java/474260/2 "2021-08-17T17:02:05Z")

</div>

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 17, 2021, 5:12pm UTC](https://forum.freecodecamp.org/t/record-problem-java/474260/3 "2021-08-17T17:12:47Z")

</div>

Thank you for letting me know!

---

<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 17, 2021, 5:13pm UTC](https://forum.freecodecamp.org/t/record-problem-java/474260/4 "2021-08-17T17:13:54Z")

</div>

Can you help me with the problem?

---

<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 17, 2021, 5:23pm UTC](https://forum.freecodecamp.org/t/record-problem-java/474260/5 "2021-08-17T17:23:48Z")

</div>

> [@lydiapernia](#):
>
> Java problem.

this is JavaScript, not Java - Java is a completely different language

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

what property are you checking for here?

---

<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 17, 2021, 8:48pm UTC](https://forum.freecodecamp.org/t/record-problem-java/474260/6 "2021-08-17T20:48:44Z")

</div>

I was checking that tracks were there for the object. So if there are items in tracks you just push one more in. Thanks for helping!

---

<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 17, 2021, 9:12pm UTC](https://forum.freecodecamp.org/t/record-problem-java/474260/7 "2021-08-17T21:12:50Z")

</div>

> [@lydiapernia](#):
>
> I was checking that tracks were there for the object.

is this how you check that?

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

---

<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 17, 2021, 9:32pm UTC](https://forum.freecodecamp.org/t/record-problem-java/474260/8 "2021-08-17T21:32:15Z")

</div>

I don’t know, I’m learning. This was a suggestion on the hints also I saw someone else using it. That line of code seems to work. It is when tracks is set to that I can’t get it it to 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 18, 2021, 6:51am UTC](https://forum.freecodecamp.org/t/record-problem-java/474260/9 "2021-08-18T06:51:43Z")

</div>

your issue is that `records[id].hasOwnProperty("prop")` is always false  
it is what I am trying to make you reflect on - what property are you actually testing? not what you want it to be testing, what it is actually doing. Read it carefully, what is it doing?

---

<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, 3:34pm UTC](https://forum.freecodecamp.org/t/record-problem-java/474260/10 "2021-08-18T15:34:37Z")

</div>

Ok ! I’ll try again but I’ve been stuck on this for a few days so if you can give me more hints I’d appreciate it!

---

<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, 3:51pm UTC](https://forum.freecodecamp.org/t/record-problem-java/474260/11 "2021-08-18T15:51:28Z")

</div>

`records[id]` does not have a property literally named `"prop"`, right? so you need to write something different on what property name to test

---

<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, 4:21pm UTC](https://forum.freecodecamp.org/t/record-problem-java/474260/12 "2021-08-18T16:21:35Z")

</div>

So I test “tracks”? I took out the hasOwnProperty and again everything works except for when the object does not have an array for the tracks.

---

<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, 4:58pm UTC](https://forum.freecodecamp.org/t/record-problem-java/474260/13 "2021-08-18T16:58:14Z")

</div>

you need to test if a certain property is present or not before being able to do a step, so you can’t remove `hasOwnProperty` completely

---

<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, 4:55pm UTC](https://forum.freecodecamp.org/t/record-problem-java/474260/14 "2021-08-18T16:55:49Z")

</div>

**Tell us what’s happening:**  
Can you tell me why the code does not work. I’ve spent too much time on this and I can’t figure it out. I need direct instruction please.  
This is the error message  
// running tests After  
updateRecords(recordCollection, 2468, “tracks”, “Free”)  
tracks should have the string 1999  
as the first element. // tests completed

Please help !

```
   **Your code so far**

```

```auto

// Setup
var recordCollection = {
 2548: {
   albumTitle: 'Slippery When Wet',
   artist: 'Bon Jovi',
   tracks: ['Let It Rock', 'You Give Love a Bad Name']
 },
 2468: {
   albumTitle: '1999',
   artist: 'Prince',
   tracks: ['1999', 'Little Red Corvette']
 },
 1245: {
   artist: 'Robert Palmer',
   tracks: []
 },
 5439: {
   albumTitle: 'ABBA Gold'
 }
};

// Only change code below this line

function updateRecords(records, id, prop, value) {
 if (prop !=="tracks" && value !== "" ){records[id][prop]= value;} 
else if (prop !=="tracks" && value === "" ){delete records[id][prop]}
else if (prop ==="tracks" && value === "" ){delete records[id][prop]}
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);}
 return records;
}
updateRecords(recordCollection, 5439, 'artist', 'ABBA');

```

```
   **Your browser information:**

```

User Agent is: `Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/92.0.4515.131 Safari/537.36 Edg/92.0.902.73`

**Challenge:** Record Collection

**Link to the challenge:**

> **[freeCodeCamp.org](https://www.freecodecamp.org/learn/javascript-algorithms-and-data-structures/basic-javascript/record-collection)**
>
> Learn to Code — For Free

---

<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, 5:00pm UTC](https://forum.freecodecamp.org/t/record-problem-java/474260/15 "2021-08-18T17:00:36Z")

</div>

I have formatted your code for readability.

```javascript
function updateRecords(records, id, prop, value) {
  if (prop !== "tracks" && value !== "") {
    records[id][prop] = value;
  } else if (prop !== "tracks" && value === "") {
    delete records[id][prop]
  } else if (prop === "tracks" && value === "") {
    delete records[id][prop]
  } 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);
  }
  return records;
}

```

I’m not sure why you duplicate the delete case?

You cannot check for an empty array like that. What happens if you try

```auto
console.log([] === [])

```

Also, if the property is undefined, it will not be equal to an empty array (even if you could check for an empty array like that).

How do you check if an object has a property?

---

<div class="post-metadata">

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

</div>

> [@lydiapernia](#):
>
> ```auto
> else if (prop !=="tracks" && value === "" ){delete records[id][prop]}
> else if (prop ==="tracks" && value === "" ){delete records[id][prop]}
> 
> ```

This seems like a logic error. You are basically deleting records[id][prop] whenever `value === ""` regardless of what the value of `prop` is. Was this your intention?

---

<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:06pm UTC](https://forum.freecodecamp.org/t/record-problem-java/474260/17 "2021-08-18T18:06:57Z")

</div>

1. Thank you for formatting it for me. I’ll do better next time.
2. I have to deletes one for when prop is tracks and one for if prop is not tracks.  
3.) I had hasOwnProperty(tracks) to check for but it still gave me one error message.  
4.) So I really need a lifeline here. I have tried everything within my limited knowledge and either it says it cannot add the track to ABBA or 1999 is not the first track in 1999. I don’t get this because i push the value to the array it should remain first.  
I tried ===[] out of desparation not logic 🙂

---

<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:11pm UTC](https://forum.freecodecamp.org/t/record-problem-java/474260/18 "2021-08-18T18:11:32Z")

</div>

> [@bbsmooth](#):
>
> basically deleting records[id][prop] whenever `value === ""` regardless of

if the prop is tracks and the value is blank you delete tracks value  
If the prop is album or artist and the value is blank you delete the album or artist  
Isn’t that what is supposed to happen?

---

<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:12pm UTC](https://forum.freecodecamp.org/t/record-problem-java/474260/19 "2021-08-18T18:12:55Z")

</div>

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

I am not sure what console.log ( ===) does?

---

<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:13pm UTC](https://forum.freecodecamp.org/t/record-problem-java/474260/20 "2021-08-18T18:13:45Z")

</div>

> [@lydiapernia](#):
>
> if the prop is tracks and the value is blank you delete tracks value  
> If the prop is album or artist and the value is blank you delete the album or artist  
> Isn’t that what is supposed to happen?

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

> [@lydiapernia](#):
>
> 3.) I had hasOwnProperty(tracks) to check for but it still gave me one error message.

I have not seen this version of your code. It’s better than what you have now

> [@lydiapernia](#):
>
> I am not sure what console.log ( ===) does?

it just prints false, you can’t use it to check if an array is empty, or if an array exist

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