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