# Record collection challenge .whats wrong with my code

**URL:** <https://forum.freecodecamp.org/t/record-collection-challenge-whats-wrong-with-my-code/262947>\
**Category:** General\
**Created:** [March 5, 2019, 2:18pm UTC](https://forum.freecodecamp.org/t/record-collection-challenge-whats-wrong-with-my-code/262947 "2019-03-05T14:18:11Z")\
**Posts on this page:** 20\
**Page:** 1

<div class="post-metadata">

**Author:** ![pcrack](https://sea3.discourse-cdn.com/freecodecamp/user_avatar/forum.freecodecamp.org/pcrack/32/142858_2.png) [@pcrack](https://forum.freecodecamp.org/u/pcrack)\
**Post date:** [March 5, 2019, 2:18pm UTC](https://forum.freecodecamp.org/t/record-collection-challenge-whats-wrong-with-my-code/262947/1 "2019-03-05T14:18:11Z")

</div>

I need help with my record collection function  
if (prop!=“tracks” && value !=" “){  
collection[id][prop] = value;  
}  
if (prop==“tracks” && collection[id].hasOwnProperty(prop)){  
collection[id][prop] = [];  
}  
if (prop==“tracks” && value!=” "){  
collection[id][prop].push(value);  
}  
if ( value = " "){  
delete collection[id][prop];  
}

---

<div class="post-metadata">

**Author:** ![chuckadams](https://sea3.discourse-cdn.com/freecodecamp/user_avatar/forum.freecodecamp.org/chuckadams/32/109651_2.png) [@chuckadams](https://forum.freecodecamp.org/u/chuckadams)\
**Post date:** [March 5, 2019, 2:19pm UTC](https://forum.freecodecamp.org/t/record-collection-challenge-whats-wrong-with-my-code/262947/2 "2019-03-05T14:19:54Z")

</div>

You have a space inbetween all your quotes, like this: `" "`.  
You should have no space there, that is it should be `""`

---

<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:** [March 5, 2019, 2:20pm UTC](https://forum.freecodecamp.org/t/record-collection-challenge-whats-wrong-with-my-code/262947/3 "2019-03-05T14:20:22Z")

</div>

> [@pcrack](#):
>
> if (prop==“tracks” && collection[id].hasOwnProperty(prop)){  
> collection[id][prop] = ;

If `collection[id]` has already a `"tracks"` property you are emptying it with this

---

<div class="post-metadata">

**Author:** ![pcrack](https://sea3.discourse-cdn.com/freecodecamp/user_avatar/forum.freecodecamp.org/pcrack/32/142858_2.png) [@pcrack](https://forum.freecodecamp.org/u/pcrack)\
**Post date:** [March 5, 2019, 2:22pm UTC](https://forum.freecodecamp.org/t/record-collection-challenge-whats-wrong-with-my-code/262947/4 "2019-03-05T14:22:08Z")

</div>

I’ve changed that but still it displays an error

---

<div class="post-metadata">

**Author:** ![pcrack](https://sea3.discourse-cdn.com/freecodecamp/user_avatar/forum.freecodecamp.org/pcrack/32/142858_2.png) [@pcrack](https://forum.freecodecamp.org/u/pcrack)\
**Post date:** [March 5, 2019, 2:23pm UTC](https://forum.freecodecamp.org/t/record-collection-challenge-whats-wrong-with-my-code/262947/5 "2019-03-05T14:23:11Z")

</div>

help me to go about 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:** [March 5, 2019, 2:23pm UTC](https://forum.freecodecamp.org/t/record-collection-challenge-whats-wrong-with-my-code/262947/6 "2019-03-05T14:23:20Z")

</div>

> [@pcrack](#):
>
> if ( value = " "){  
> delete collection[id][prop];  
> }

This will always execute, as that is an assignment operator you are assigning a value to value not checking it

---

<div class="post-metadata">

**Author:** ![pcrack](https://sea3.discourse-cdn.com/freecodecamp/user_avatar/forum.freecodecamp.org/pcrack/32/142858_2.png) [@pcrack](https://forum.freecodecamp.org/u/pcrack)\
**Post date:** [March 5, 2019, 2:24pm UTC](https://forum.freecodecamp.org/t/record-collection-challenge-whats-wrong-with-my-code/262947/7 "2019-03-05T14:24:37Z")

</div>

I already changed it from an assignment operator to == for comparison.

---

<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:** [March 5, 2019, 2:24pm UTC](https://forum.freecodecamp.org/t/record-collection-challenge-whats-wrong-with-my-code/262947/8 "2019-03-05T14:24:40Z")

</div>

If the object does not have the `tracks` property you need to create it with a value of an empty array, if instead it does have it already you don’t have to do anything, you just need a small correction to your current code

---

<div class="post-metadata">

**Author:** ![chuckadams](https://sea3.discourse-cdn.com/freecodecamp/user_avatar/forum.freecodecamp.org/chuckadams/32/109651_2.png) [@chuckadams](https://forum.freecodecamp.org/u/chuckadams)\
**Post date:** [March 5, 2019, 2:24pm UTC](https://forum.freecodecamp.org/t/record-collection-challenge-whats-wrong-with-my-code/262947/9 "2019-03-05T14:24:54Z")

</div>

> [@pcrack](#):
>
> if (prop==“tracks” && collection[id].hasOwnProperty(prop)){  
> collection[id][prop] = ;

Your problem is here; your logic is inverted. You want to set the tracks to an empty list if it _doesn’t_ have a tracks property.

Try this:  
`if (prop==“tracks” && !(collection[id].hasOwnProperty(prop))){`

I haven’t looked at the rest of the code hard enough to see if you have more errors in it, but make this fix and see if more tests pass.

---

<div class="post-metadata">

**Author:** ![pcrack](https://sea3.discourse-cdn.com/freecodecamp/user_avatar/forum.freecodecamp.org/pcrack/32/142858_2.png) [@pcrack](https://forum.freecodecamp.org/u/pcrack)\
**Post date:** [March 5, 2019, 2:30pm UTC](https://forum.freecodecamp.org/t/record-collection-challenge-whats-wrong-with-my-code/262947/10 "2019-03-05T14:30:26Z")

</div>

no its not working yet

---

<div class="post-metadata">

**Author:** ![chuckadams](https://sea3.discourse-cdn.com/freecodecamp/user_avatar/forum.freecodecamp.org/chuckadams/32/109651_2.png) [@chuckadams](https://forum.freecodecamp.org/u/chuckadams)\
**Post date:** [March 5, 2019, 2:31pm UTC](https://forum.freecodecamp.org/t/record-collection-challenge-whats-wrong-with-my-code/262947/11 "2019-03-05T14:31:49Z")

</div>

Which tests are failing? Have you tried tracing through your logic, going through each step in your head? Try adding some `console.log` statements in your code to see which conditions are firing unexpectedly.

---

<div class="post-metadata">

**Author:** ![pcrack](https://sea3.discourse-cdn.com/freecodecamp/user_avatar/forum.freecodecamp.org/pcrack/32/142858_2.png) [@pcrack](https://forum.freecodecamp.org/u/pcrack)\
**Post date:** [March 5, 2019, 2:32pm UTC](https://forum.freecodecamp.org/t/record-collection-challenge-whats-wrong-with-my-code/262947/12 "2019-03-05T14:32:29Z")

</div>

All along this the only error am getting whatsoever  
After `updateRecords(2468, "tracks", "Free")` , `tracks` should have `"1999"` as the first element

---

<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:** [March 5, 2019, 2:34pm UTC](https://forum.freecodecamp.org/t/record-collection-challenge-whats-wrong-with-my-code/262947/13 "2019-03-05T14:34:25Z")

</div>

Can you post your updated code?

---

<div class="post-metadata">

**Author:** ![chuckadams](https://sea3.discourse-cdn.com/freecodecamp/user_avatar/forum.freecodecamp.org/chuckadams/32/109651_2.png) [@chuckadams](https://forum.freecodecamp.org/u/chuckadams)\
**Post date:** [March 5, 2019, 2:36pm UTC](https://forum.freecodecamp.org/t/record-collection-challenge-whats-wrong-with-my-code/262947/14 "2019-03-05T14:36:16Z")

</div>

> [@pcrack](#):
>
> if ( value = " "){

This is another problem – it should be `===`, not `=`

---

<div class="post-metadata">

**Author:** ![pcrack](https://sea3.discourse-cdn.com/freecodecamp/user_avatar/forum.freecodecamp.org/pcrack/32/142858_2.png) [@pcrack](https://forum.freecodecamp.org/u/pcrack)\
**Post date:** [March 5, 2019, 2:42pm UTC](https://forum.freecodecamp.org/t/record-collection-challenge-whats-wrong-with-my-code/262947/15 "2019-03-05T14:42:38Z")

</div>



---

<div class="post-metadata">

**Author:** ![pcrack](https://sea3.discourse-cdn.com/freecodecamp/user_avatar/forum.freecodecamp.org/pcrack/32/142858_2.png) [@pcrack](https://forum.freecodecamp.org/u/pcrack)\
**Post date:** [March 5, 2019, 2:44pm UTC](https://forum.freecodecamp.org/t/record-collection-challenge-whats-wrong-with-my-code/262947/16 "2019-03-05T14:44:54Z")

</div>

![Screenshot%20at%202019-03-05%2017-44-41](https://global.discourse-cdn.com/freecodecamp/original/3X/a/f/afbd3b4f0b98ba5a389e54eb5ddb9a292fa23cf3.png)

---

<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:** [March 5, 2019, 2:47pm UTC](https://forum.freecodecamp.org/t/record-collection-challenge-whats-wrong-with-my-code/262947/17 "2019-03-05T14:47:34Z")

</div>

Don’t write a series of `if` statements on the same line  
Also, please don’t use a screenshot, post your code so it is easier to copy it to test it  
Or if you post a screenshot at least include the result of the tests

---

<div class="post-metadata">

**Author:** ![pcrack](https://sea3.discourse-cdn.com/freecodecamp/user_avatar/forum.freecodecamp.org/pcrack/32/142858_2.png) [@pcrack](https://forum.freecodecamp.org/u/pcrack)\
**Post date:** [March 5, 2019, 2:53pm UTC](https://forum.freecodecamp.org/t/record-collection-challenge-whats-wrong-with-my-code/262947/18 "2019-03-05T14:53:42Z")

</div>

![Screenshot%20at%202019-03-05%2017-54-12](https://global.discourse-cdn.com/freecodecamp/original/3X/7/0/705721fc8773ec6b2c0dd10c921db4ef300b0816.png)

---

<div class="post-metadata">

**Author:** ![lasjorg](https://sea3.discourse-cdn.com/freecodecamp/user_avatar/forum.freecodecamp.org/lasjorg/32/280761_2.png) [@lasjorg](https://forum.freecodecamp.org/u/lasjorg)\
**Post date:** [March 5, 2019, 3:48pm UTC](https://forum.freecodecamp.org/t/record-collection-challenge-whats-wrong-with-my-code/262947/19 "2019-03-05T15:48:21Z")

</div>

It seems like it is passing for me if I got your code right. Copy your function and then reset the challenge, paste it back in and run the test again.

---

<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:** [January 16, 2021, 12:59pm UTC](https://forum.freecodecamp.org/t/record-collection-challenge-whats-wrong-with-my-code/262947/20 "2021-01-16T12:59:24Z")

</div>

Closed on January 16, 2021, 12:59pm UTC


