I'm stuck on Record Collection. and idk why

I stuck on one of the test which is

After updateRecords(collection, 2468, "tracks", "Free") , tracks should have 1999 as the first element.

And I couldn’t figure it out what was wrong with my code

Here is my code:

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

console.log(updateRecords(collection, 2468, 'tracks', 'Free'));

and this is the output (Notice: the [“Free”, " Free"]

{ '1245': { artist: 'Robert Palmer', tracks: [] },
   { albumTitle: '1999',
     artist: 'Prince',
     tracks: [ 'Free', 'Free' ] },
   { albumTitle: 'Slippery When Wet',
     artist: 'Bon Jovi',
     tracks: [ 'Let It Rock', 'You Give Love a Bad Name' ] },
  '5439': { albumTitle: 'ABBA Gold' } }

Your browser information:

User Agent is: Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/87.0.4280.88 Safari/537.36 Edg/87.0.664.66.

Challenge: Record Collection

Link to the challenge:

both of this execute in that case, so you get an array of length 2


Adding to @ilenia hint, just be aware that your collection object will never have ‘tracks’ as the property. The objects within the collection object may or may not have ‘tracks’ as the property.


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