# Basic JavaScript - Record Collection

**URL:** <https://forum.freecodecamp.org/t/basic-javascript-record-collection/619727>\
**Category:** Curriculum Help\
**Tags:** javascript\
**Created:** [June 30, 2023, 3:49pm UTC](https://forum.freecodecamp.org/t/basic-javascript-record-collection/619727 "2023-06-30T15:49:22Z")\
**Posts on this page:** 20\
**Page:** 1

<div class="post-metadata">

**Author:** ![jpboggess](https://sea3.discourse-cdn.com/freecodecamp/user_avatar/forum.freecodecamp.org/jpboggess/32/323338_2.png) [@jpboggess](https://forum.freecodecamp.org/u/jpboggess)\
**Post date:** [June 30, 2023, 3:49pm UTC](https://forum.freecodecamp.org/t/basic-javascript-record-collection/619727/1 "2023-06-30T15:49:22Z")

</div>

please give me a detailed explanation as to what i am doing wrong. i am extremely confused both with the problem and how its written.  
**Tell us what’s happening:**  
Describe your issue in detail here.

**Your code so far**

```javascript
// Setup
const 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) {
  return records;
 if(value===""){
   delete records[id][prop];//If value is an empty string, delete the given prop property from the album.
 }
 if(prop!=="tracks"&&value!==""){
   record[id][value]=[prop];
 }//If prop isn't tracks and value isn't an empty string, assign the value to that album's prop.
If(prop==="tracks"&&value!==""&& "album"==="tracks"==="");{
  
    records[id][prop]= [];
   [value]= push[value]; 
}
  }

 //If prop is tracks and value isn't an empty string, you need to update the album's tracks array. First, if the album does not have a tracks property, assign it an empty array. Then add the value as the last item in the album's tracks array.
   
 
 

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

```

**Your browser information:**

User Agent is: `Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:109.0) Gecko/20100101 Firefox/114.0`

**Challenge:** Basic JavaScript - 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:** [June 30, 2023, 3:50pm UTC](https://forum.freecodecamp.org/t/basic-javascript-record-collection/619727/2 "2023-06-30T15:50:02Z")

</div>

> [@jpboggess](#):
>
> `return records;`

A return statement immediately stops a function

---

<div class="post-metadata">

**Author:** ![jpboggess](https://sea3.discourse-cdn.com/freecodecamp/user_avatar/forum.freecodecamp.org/jpboggess/32/323338_2.png) [@jpboggess](https://forum.freecodecamp.org/u/jpboggess)\
**Post date:** [June 30, 2023, 3:52pm UTC](https://forum.freecodecamp.org/t/basic-javascript-record-collection/619727/3 "2023-06-30T15:52:51Z")

</div>

what else because now record is undefined

---

<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:** [June 30, 2023, 3:56pm UTC](https://forum.freecodecamp.org/t/basic-javascript-record-collection/619727/4 "2023-06-30T15:56:13Z")

</div>

Record is undefined. It’s not a variable in your code anywhere. Check your spelling

---

<div class="post-metadata">

**Author:** ![jpboggess](https://sea3.discourse-cdn.com/freecodecamp/user_avatar/forum.freecodecamp.org/jpboggess/32/323338_2.png) [@jpboggess](https://forum.freecodecamp.org/u/jpboggess)\
**Post date:** [June 30, 2023, 3:57pm UTC](https://forum.freecodecamp.org/t/basic-javascript-record-collection/619727/5 "2023-06-30T15:57:19Z")

</div>

records\* same issue.

---

<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:** [June 30, 2023, 3:58pm UTC](https://forum.freecodecamp.org/t/basic-javascript-record-collection/619727/6 "2023-06-30T15:58:10Z")

</div>

When you fix your typo it still says record is undefined? That means you didn’t fix your typo.

---

<div class="post-metadata">

**Author:** ![jpboggess](https://sea3.discourse-cdn.com/freecodecamp/user_avatar/forum.freecodecamp.org/jpboggess/32/323338_2.png) [@jpboggess](https://forum.freecodecamp.org/u/jpboggess)\
**Post date:** [June 30, 2023, 4:00pm UTC](https://forum.freecodecamp.org/t/basic-javascript-record-collection/619727/7 "2023-06-30T16:00:30Z")

</div>

```auto
const 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(value===""){
   delete records[id][prop];//If value is an empty string, delete the given prop property from the album.
 }
 if(prop!=="tracks"&&value!==""){
   record[id][value]=[prop];
 }//If prop isn't tracks and value isn't an empty string, assign the value to that album's prop.
If(prop==="tracks"&&value!==""&& "album"==="tracks"==="");{
  
    records[id][prop]= [];
   [value]= push[value]; 
}
return records;
  }

```

//If prop is tracks and value isn’t an empty string, you need to update the album’s tracks array. First, if the album does not have a tracks property, assign it an empty array. Then add the value as the last item in the album’s tracks array.

updateRecords(recordCollection, 5439, ‘artist’, ‘ABBA’);

- Failed: After `updateRecords(recordCollection, 1245, "tracks", "Addicted to Love")`, `tracks` should have the string `Addicted to Love` as the last element.

- Failed: After `updateRecords(recordCollection, 2468, "tracks", "Free")`, `tracks` should have the string `1999` as the first element.

- Failed: After `updateRecords(recordCollection, 2548, "tracks", "")`, `tracks` should not be set

- Failed: After `updateRecords(recordCollection, 1245, "albumTitle", "Riptide")`, `albumTitle` should be the string `Riptide`

27

26

23

24

25

22

28

29

30

31

32

33

34

35

36

37

38

39

40

41

42

43

44

// running tests After

```auto
updateRecords(recordCollection, 5439, "artist", "ABBA")

```

,

```auto
artist

```

should be the string

```auto
ABBA

```

After

```auto
updateRecords(recordCollection, 5439, "tracks", "Take a Chance on Me")

```

,

```auto
tracks

```

should have the string

```auto
Take a Chance on Me

```

as the last and only element. After

```auto
updateRecords(recordCollection, 2548, "artist", "")

```

,

```auto
artist

```

should not be set After

```auto
updateRecords(recordCollection, 1245, "tracks", "Addicted to Love")

```

,

```auto
tracks

```

should have the string

```auto
Addicted to Love

```

as the last element. After

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

```

,

```auto
tracks

```

should have the string

```auto
1999

```

as the first element. After

```auto
updateRecords(recordCollection, 2548, "tracks", "")

```

,

```auto
tracks

```

should not be set After

```auto
updateRecords(recordCollection, 1245, "albumTitle", "Riptide")

```

,

```auto
albumTitle

```

should be the string

```auto
Riptide

```

// tests completed // console output ReferenceError: record is not defined

---

<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:** [June 30, 2023, 4:00pm UTC](https://forum.freecodecamp.org/t/basic-javascript-record-collection/619727/8 "2023-06-30T16:00:53Z")

</div>

Yes, you did not fix your typo

---

<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:** [June 30, 2023, 4:01pm UTC](https://forum.freecodecamp.org/t/basic-javascript-record-collection/619727/9 "2023-06-30T16:01:34Z")

</div>

I’ve edited your code 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:** ![jpboggess](https://sea3.discourse-cdn.com/freecodecamp/user_avatar/forum.freecodecamp.org/jpboggess/32/323338_2.png) [@jpboggess](https://forum.freecodecamp.org/u/jpboggess)\
**Post date:** [June 30, 2023, 4:05pm UTC](https://forum.freecodecamp.org/t/basic-javascript-record-collection/619727/10 "2023-06-30T16:05:24Z")

</div>

i found the typo, and that didnt fix the issue

---

<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:** [June 30, 2023, 4:10pm UTC](https://forum.freecodecamp.org/t/basic-javascript-record-collection/619727/11 "2023-06-30T16:10:14Z")

</div>

> [@jpboggess](#):
>
> ` record[id][value]=[prop];`

The typo is still in your code here. You fixed this?

---

<div class="post-metadata">

**Author:** ![jpboggess](https://sea3.discourse-cdn.com/freecodecamp/user_avatar/forum.freecodecamp.org/jpboggess/32/323338_2.png) [@jpboggess](https://forum.freecodecamp.org/u/jpboggess)\
**Post date:** [June 30, 2023, 4:13pm UTC](https://forum.freecodecamp.org/t/basic-javascript-record-collection/619727/12 "2023-06-30T16:13:28Z")

</div>

yes and i still get the same errors

---

<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:** [June 30, 2023, 4:14pm UTC](https://forum.freecodecamp.org/t/basic-javascript-record-collection/619727/13 "2023-06-30T16:14:06Z")

</div>

If you still get an error saying `ReferenceError: record is not defined`, then you did not fix the typo

---

<div class="post-metadata">

**Author:** ![jpboggess](https://sea3.discourse-cdn.com/freecodecamp/user_avatar/forum.freecodecamp.org/jpboggess/32/323338_2.png) [@jpboggess](https://forum.freecodecamp.org/u/jpboggess)\
**Post date:** [June 30, 2023, 4:16pm UTC](https://forum.freecodecamp.org/t/basic-javascript-record-collection/619727/14 "2023-06-30T16:16:59Z")

</div>

ok look stop trolling me i fixed the "records " problem it says my if statement is not defined. ive been at this for 2 days a total 12 hours please if youre going to give me a reply, actually look and read my code and fix it or dont answer and have someone who will take over.

---

<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:** [June 30, 2023, 4:17pm UTC](https://forum.freecodecamp.org/t/basic-javascript-record-collection/619727/15 "2023-06-30T16:17:44Z")

</div>

I’m not trolling you. You said

> [@jpboggess](#):
>
> i still get the same errors

If your errors are the exact same, then you still have `record` instead of `records`. If the errors are not the exact same, then please show your updated code.

---

<div class="post-metadata">

**Author:** ![jpboggess](https://sea3.discourse-cdn.com/freecodecamp/user_avatar/forum.freecodecamp.org/jpboggess/32/323338_2.png) [@jpboggess](https://forum.freecodecamp.org/u/jpboggess)\
**Post date:** [June 30, 2023, 4:18pm UTC](https://forum.freecodecamp.org/t/basic-javascript-record-collection/619727/16 "2023-06-30T16:18:53Z")

</div>

```auto
// Setup
const 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(value===""){
   delete records[id][prop];//If value is an empty string, delete the given prop property from the album.
 }
 if(prop!=="tracks"&&value!==""){
   records[id][value]=[prop];
 }//If prop isn't tracks and value isn't an empty string, assign the value to that album's prop.
if(prop==="tracks"&&value!==""&& "album"==="tracks"===""){
  records[id][prop]= [];
   [value]= push[value]; 
}
return records;
  }

 //If prop is tracks and value isn't an empty string, you need to update the album's tracks array. First, if the album does not have a tracks property, assign it an empty array. Then add the value as the last item in the album's tracks array.
   
 
 

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

```

---

<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:** [June 30, 2023, 4:19pm UTC](https://forum.freecodecamp.org/t/basic-javascript-record-collection/619727/17 "2023-06-30T16:19:13Z")

</div>

I’ve edited your code 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:** ![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:** [June 30, 2023, 4:23pm UTC](https://forum.freecodecamp.org/t/basic-javascript-record-collection/619727/18 "2023-06-30T16:23:05Z")

</div>

I’m going to apply some conventional formatting to your code so its easier to read

```js
function updateRecords(records, id, prop, value) {
 if (value === "") {
   // If value is an empty string, delete the given prop property from the album.
   delete records[id][prop];
 }
 if (prop !== "tracks" && value !== "") {
   // If prop isn't tracks and value isn't an empty string, assign the value to that album's prop.
   records[id][value] = [prop];
 }
 if (prop === "tracks" && value !=="" && "album" === "tracks" === "") {
   records[id][prop] = [];
   [value] = push[value]; 
  }
  return records;
}

```

Now, first question. Why this line:

> [@jpboggess](#):
>
> ` records[id][value]=[prop];`

Second question:

> [@jpboggess](#):
>
> `if(prop==="tracks"&&value!==""&& "album"==="tracks"===""){`

What does this condition mean?

Third question:

> [@jpboggess](#):
>
> ```auto
> records[id][prop]= [];
> [value]= push[value]; 
> 
> ```

What are these lines doing?

---

<div class="post-metadata">

**Author:** ![jpboggess](https://sea3.discourse-cdn.com/freecodecamp/user_avatar/forum.freecodecamp.org/jpboggess/32/323338_2.png) [@jpboggess](https://forum.freecodecamp.org/u/jpboggess)\
**Post date:** [June 30, 2023, 4:33pm UTC](https://forum.freecodecamp.org/t/basic-javascript-record-collection/619727/19 "2023-06-30T16:33:13Z")

</div>

1. assign the value to the album’s prop im not sure how to do that properly
2. if prop equals tracks and value equals blank string and album equals tracks and tracks equals blank string
3. assigning empty array to property if it meets the requirements of if statement and giving value a value.

- please explain how this is suppose to be written because i am having trouble grasping combing the concepts as the course continues.

---

<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:** [June 30, 2023, 4:38pm UTC](https://forum.freecodecamp.org/t/basic-javascript-record-collection/619727/20 "2023-06-30T16:38:26Z")

</div>

> [@jpboggess](#):
>
> assign the value to the album’s prop im not sure how to do that properly

The issue here is that you 're putting the value into an array. But the only property that uses arrays in ‘tracks’

> [@jpboggess](#):
>
> album equals tracks and tracks equals blank string

This is where you have a problem. Two different strings can never equal each other, so this can’t be a condition that works.

> [@jpboggess](#):
>
> assigning empty array to property if it meets the requirement

You should not always overwrite the tracks with an empty array.

What does that last bullet point say? We need to look at it sentence by sentence.

[Next page](https://forum.freecodecamp.org/t/basic-javascript-record-collection/619727.md?page=2)
