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 != ''){
    object[id][prop].push(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: [] },
  '2468': 
   { albumTitle: '1999',
     artist: 'Prince',
     tracks: [ 'Free', 'Free' ] },
  '2548': 
   { 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

4 Likes

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.

3 Likes

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