I’m doing freecodecamp’s JS course and there’s a certain exercise I’m stuck with.
Here’s the code:
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) {
if(prop !== 'tracks' && value !== ''){
records.id[prop] = value;
}
return records;
}
updateRecords(recordCollection, 5439, 'artist', 'ABBA');
The line " records.id[prop] = value" gives me the error "TypeError: Cannot set properties of undefined ".
I don’t understand this since from what I know this should work. Any help?
Edit: by the way, records[id][prop] does work, which I’m not sure why. id is a given number which represents a property, why can’t I call it with dot notation?