Basic JavaScript - Record Collection

Tell us what’s happening:

Struggling to understand, I m trying my best to make the problem small as possible but my head hurts, not sure where to start e.g. the first test says ‘if value is empty then delete the prop’ now I got the following

  if(records[id][prop] == ''){
      delete records[prop]
  }

but where should I put the word value as i cannot think outside of records[id][prop] == ''
How can I make the problem small as possible and build on top of it?

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(records[id][prop] == ''){
      delete records[prop]
  }
  console.log(records)
  return records;
}

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

Your browser information:

User Agent is: Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/117.0.0.0 Safari/537.36

Challenge Information:

Basic JavaScript - Record Collection

Okay. Here’s the directions.

  1. “If value is an empty string, delete the given prop property from the album.”

In your code value isn’t used.

Happy coding. If you need additional help, let me know. :slightly_smiling_face:

2 Likes

I could only think of

if(records[id][prop] !== value){
      delete records[prop]
  }

again I m confused coz =='' vs !== value

1 Like

This doesn’t look like it checks ‘if value is an empty string’

1 Like

value is a parameter, it can contain an empty string if the function is called with an empty string.

After updateRecords(recordCollection, 2548, "artist", "") , artist should not be set

function updateRecords(records, id, prop, value)

So value can be an empty string which you should check for.

1 Like

Does it mean I am missing for loop?

Do u mean like this

 if(value == ''){
      delete records[prop]
  }

Yes, that is how you would check if value is an empty string.

I’d suggest you get in the habit of using === unless you need the type coercion of ==. An empty string is also a falsy value so that is also an option if (!value)


 if(value == ''){
      delete records[prop]
  }

You are missing something here. How do you know what object to delete the property from? By its…?

1 Like

key. if the answer is key, I am doing that when I do delete records[prop] which says delete record with the given prop.
Do not answer the solution, I really wanna know what I m doing wrong. where is my missing logic

upong reading my own line of code, I can confirm it was not checking if value is an empty string

The records object won’t have the prop. The records object is made up of individual record objects and those have properties.

1 Like

I thought prop is short for property, where property means key

Yes. That doesn’t change that I said though.

What is inside of the records object?

1 Like

Each record has a id which has a object which has its own prop and value i.e. key and value. Am I right so far?

I can watch a video or get a hint solution but problem is I really wanna get into finding the problem solution own my own.

Today I went to see hints and got 90% of it

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

What shocks me most, why I was making it so complex like if(records[id][props] === value) thinking it will check if(records[id][props] === ''). My question now would be, why people like me make it so complated and is it normal, what is best way to approach a problem especially complex one.

As said, plenty of people struggle with this one and it isn’t that easy to get right. But it would have been better if you posted your updated code and continued to get help with it.

Code often starts out a bit verbose, after you get it working you can refactor the code. The opposite can also be true, you may find a bunch of edge cases later on that you didn’t account for, and the code balloons.

In the end, it comes down to experience.


There is definitely an argument to be made that the function has too many responsibilities. You are more likely to have three functions, one for creation, one for updating, and one for deletion. The way it uses an empty string argument to delete data is a fairly questionable API decision I would say.

I did, it is linked [here] but no help came for days so I have to look at hint(Basic JavaScript - Record Collection - #15 by mahassan)

It looks like you didn’t answer for 43 hours, replied, waited 32 hours, and then looked at the answer? Unfortunately those gaps pushed the conversation into some personal business of mine (and sorta broke up the flow!).

Did you try anything else between you posting your code 5 days ago in the original post and looking at the answer? There was a pretty big gap with no new code shown.


I’d definitely not look at answers - this becomes increasingly important from this point on.

This is a bit strangly phrased but seems correct to me.

1 Like

I just saw the hint

Sorry I didn’t understand what you mean

You waited days before replying. I had other things to do in the meantime.

Ah, that’s not what you said above. I definitely don’t recommend looking at the answers.