# A little Help please

**URL:** <https://forum.freecodecamp.org/t/a-little-help-please/364981>\
**Category:** Curriculum Help\
**Tags:** javascript\
**Created:** [March 29, 2020, 12:08am UTC](https://forum.freecodecamp.org/t/a-little-help-please/364981 "2020-03-29T00:08:33Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![Lumen-X](https://sea3.discourse-cdn.com/freecodecamp/user_avatar/forum.freecodecamp.org/lumen-x/32/139676_2.png) [@Lumen-X](https://forum.freecodecamp.org/u/Lumen-X)\
**Post date:** [March 29, 2020, 12:08am UTC](https://forum.freecodecamp.org/t/a-little-help-please/364981/1 "2020-03-29T00:08:33Z")

</div>

**Tell us what’s happening:**  
My code is failing this test  
After `updateRecords(2468, "tracks", "Free")` , `tracks` should have `"1999"` as the first element.

**Your code so far**

```js

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

// Only change code below this line
function updateRecords(id, prop, value) {
if(value === ""){
  delete collection[id][prop];
}else if(prop === "tracks"){
  if(collection[id][prop] === []){
    collection[id][prop].push(value)
  }else{
    collection[id][prop] = [];
    collection[id][prop].push(value);
  }
}else{
  collection[id][prop] = value;
}

return collection;
}

updateRecords(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/80.0.3987.149 Safari/537.36`.

**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:** ![MPA81](https://sea3.discourse-cdn.com/freecodecamp/user_avatar/forum.freecodecamp.org/mpa81/32/138046_2.png) [@MPA81](https://forum.freecodecamp.org/u/MPA81)\
**Post date:** [March 29, 2020, 12:36am UTC](https://forum.freecodecamp.org/t/a-little-help-please/364981/2 "2020-03-29T00:36:55Z")

</div>

I think the problem you are facing may be related to your initializing a _tracks_ property that already exists, in that first _else_ statement.

---

<div class="post-metadata">

**Author:** ![kitfoster](https://sea3.discourse-cdn.com/freecodecamp/user_avatar/forum.freecodecamp.org/kitfoster/32/136607_2.png) [@kitfoster](https://forum.freecodecamp.org/u/kitfoster)\
**Post date:** [March 29, 2020, 1:20am UTC](https://forum.freecodecamp.org/t/a-little-help-please/364981/3 "2020-03-29T01:20:41Z")

</div>

There is a logic error in your else if statement.

In this statement:

```auto
  if(collection[id][prop] === []){  
    collection[id][prop].push(value)
  }

```

you are looking for an array that is empty. But this doesn’t exist - the collection either has a tracks property with an array of track names, or the track property doesn’t exist. This means the code in these curly brackets never executes.

This means your default always executes:

```auto
else{
    collection[id][prop] = [];
    collection[id][prop].push(value);
  }

```

and this code resets the tracks property to empty, which erases all track names already stored.

The instructions say: If the prop === “tracks” the instructions say you need to either create an empty array if the album doesn’t have a tracks property before adding the new value OR push the value onto the existing tracks arrays. Your code is currently always creating an empty array and then adding the new value, so check the if statement I quoted above and see if you can fix it to push the value onto the existing tracks array.

Hope that helps!

---

<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:** [June 1, 2021, 12:59pm UTC](https://forum.freecodecamp.org/t/a-little-help-please/364981/4 "2021-06-01T12:59:12Z")

</div>

Closed on June 1, 2021, 12:59pm UTC


