Https://www.freecodecamp.org/learn/javascript-algorithms-and-data-structures/basic-javascript/record-collection

i cant find bug in this code can anybody help me in this.

// 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'
    tracks: []
     }
};
  
// Only change code below this line
function updateRecords(records, id, prop, value) {
  if (!value){
    delete records[id][prop]
  } else if (prop != 'tracks') {
    records[id][prop] =value
  } else {
    if (!records[id].hasOwnProperty('tracks')) 
      records[id].tracks = []
  }
 
return records;
}

console.log(updateRecords(recordCollection, 5439, 'album title'));

Hey @adnan1,

Good job on getting this far. There are just a couple things to address here. In the original data set that is supposed to remain unmodified, there is a comma missing in number 5439:

It should be:

 5439: {
    albumTitle: 'ABBA Gold',
    tracks: []
 }

Without that comma, that variable’s data becomes invalid and turns into an error.

Also, in the final else block, you have to remember to push the value you want on to the tracks for that specific record.

If you have a question about a specific challenge as it relates to your written code for that challenge and need some help, click the Ask for Help button located on the challenge (it looks like a question mark). This button only appears if you have tried to submit an answer at least three times.

The Ask for Help button will create a new topic with all code you have written and include a link to the challenge also. You will still be able to ask any questions in the post before submitting it to the forum.

Thank you.

2 Likes