Records - JavaScript

Hi, love to hear some feedback to why are some tests failing despite logging correct outputs. thank you very much!

// 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'
  }
};

function updateRecords(records, id, prop, value) {
  const newrecord = records[id];
  const keys = Object.keys(newrecord);
    
  if (value == '') {delete newrecord[prop];}
    
  else if (prop == 'albumTitle')
    {newrecord['albumTitle'] = value;}

  else if (prop == 'artist') 
    {newrecord['artist'] = value;}
             
  else if (prop == 'tracks' && keys.includes('tracks')) 
    {const tracks_list = newrecord['tracks'];
      tracks_list.push(value);
      newrecord['tracks'] = tracks_list;}
          
  else {const tracks_list = []; 
      tracks_list.push(value);
      newrecord["tracks"] = tracks_list;}
console.log(newrecord); 
          
return newrecord;
}

I have logged the output below. Would appreciate some explanations to why it is failing the tests.

tests completed // console output { albumTitle: 'ABBA Gold', artist: 'ABBA' } { albumTitle: 'ABBA Gold', artist: 'ABBA' } { albumTitle: 'ABBA Gold', tracks: [ 'Take a Chance on Me' ] } { albumTitle: 'Slippery When Wet', tracks: [ 'Let It Rock', 'You Give Love a Bad Name' ] } { artist: 'Robert Palmer', tracks: [ 'Addicted to Love' ] } { albumTitle: '1999', artist: 'Prince', tracks: [ '1999', 'Little Red Corvette', 'Free' ] } { albumTitle: 'Slippery When Wet', artist: 'Bon Jovi' } { artist: 'Robert Palmer', tracks: [], albumTitle: 'Riptide' }

It looks like you’re returning your newrecord object from the function, but what do the instructions say to return?

thank you for checking. please correct me if I am wrong:

i can just call records to be newrecord in the end which I didn’t so I was assuming that it should work find. I just renamed it records and results are the same as before like i expected.

The instructions say

Your function must always return the entire record collection object.

Are you returning the entire record collection object? Or are you returning a single record object?

Hi, Yes, it’s returning the whole record, see the log I attached with the question.

Yes, you’re returning a single whole record. That’s not the entire record collection though. You need to return the entire record collection.

Oh, I see. thank you for your help. I will fix it.

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