Basic JavaScript - Record Collection

Tell us what’s happening:

Describe your issue in detail here.

Hello all, this is my first time posting in the forum.

I have been struggling with that challenge for about a week now.
I almost passed all the conditions, but I can’t seem to get the " After updateRecords(recordCollection, 2468, "tracks", "Free"), tracks should have the string 1999 as the first element." right.

I would be glad if anyone had an idea of what is wrong with my code.
Please and thank you!

P.S: English is not my native language, kindly excuse the mistakes that might be in my speech.

Your code so far

// 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];
  } else if (prop != 'tracks' && value != "") {
     records[id][prop] = value;
  } else if (prop == 'tracks' && value != "") {
    if (records.hasOwnProperty([id][prop]) === false) {
     records[id][prop] = [];
  return records;

console.log(updateRecords(recordCollection, 2468, "tracks", "Free"));

Your browser information:

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

Challenge Information:

Basic JavaScript - Record Collection

1 Like

Your issue is here. When do you want to push?


Am I not supposed to add/push the value after creating an empty array?

1 Like

Do you only want to add the track if the tracks array doesn’t exist and ignore the track if the already is a tracks array?


I do not want to ignore it.
Isn’t the " if (records.hasOwnProperty([id][prop]) === false) " supposed to work only if the tracks array doesn’t exist and if it exists already then just push the value at the end?
I don’t get why the value is being pushed but the already existing tracks are being deleted.

The existing tracks aren’t being deleted anywhere in that block.

Right now, your logic says

  1. if the tracks array doesn’t exist, then create it and add the new track
  2. otherwise do nothing
1 Like

I have also tried

if (records.hasOwnProperty([id][prop]) === false) {
     records[id][prop] = [];
    } else if (record.hasOwnProperty([id][prop])) {

but it didn’t change anything.

Why put the push inside of an if clause at all?

Create the tracks array if it doesn’t exist.

Then add the new track to the array no matter what.

Ah, just saw the other issue.

What is this syntax saying?

If records has a tracks property then… ?

Why would the entire ‘records’ object have a tracks property though? The entire records object consists of individual records. The individual records themselves have properties like tracks and name.

Like here.

So instead of using the entire records.hasOwnProperty([id][prop]) I should use records.hasOwnProperty(value)?

No. That checks if the entire records object has a property named by the ‘value’ variable.

What do you want to check for the tracks property? It isn’t the entire set of records.

I want to check if the tracks property exists or not.

Yes… But what should have the tracks property? It is not the entire records object.

A value?
I am not sure about the meaning of “what should have the tracks property”

Where should the track go? What are you supposed to add the track to?

Put another way, where you put the tracks array and where you look for the tracks array should agree

Try console logging what your code is doing.
This should help identify where the problem is.

Oh my, I finally figured it out. [prop] doesn’t exist in the original object, so I can’t search for it.
Thank you so much for your help. Just knowing where I should search for an error was really helpful.
Now I can move on! :partying_face: :partying_face:

1 Like

Huzzah! This is a lesson that really keeps into how hard it is to go back and forth between English and code, so it’s definitely a hard one!

1 Like

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