Tell us what’s happening:
Describe your issue in detail here.
I’ve been stuck on this question for a while and don’t know what’s wrong with my approach. I’m thinking it might be a syntax error but I’m not sure. My thought process is to check what the id is → check if value is empty → if it’s not empty than set value as the property OR add the array then add the value to the array. If someone know’s what’s wrong with my code please let me know
**Your code so far**
// 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'
}
};
// Only change code below this line
function updateRecords(records, id, prop, value) {
if (id == "artist" && value != ""){
id.prop = value;
}
else if (id == "artist" && value == ""){
delete id.prop;
}
else if (id == "tracks" && value != ""){
if (id.hasOwnProperty(prop)){
prop.push(value);
} else if ((id.hasOwnProperty(prop)) == false){
id.prop = [];
prop.push(value);
}
}
else if (id == "tracks" && value == ""){
if (id.hasOwnProperty(prop)){
delete id.prop;
} else if ((id.hasOwnProperty(prop)) == false){
return records;
}
}
else if (id == "albumTitle" && value != ""){
id.prop = value;
}
else if (id == "albumTitle" && value == ""){
if (id.hasOwnProperty(prop)){
delete id.prop;
} else if ((id.hasOwnProperty(prop)) == false){
return records;
}
}
return records;
}
updateRecords(recordCollection, 5439, 'artist', 'ABBA');
**Your browser information:**
User Agent is: Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/105.0.0.0 Safari/537.36
Oh is id not an object? I thought that id was a nested object inside the object recordCollection. Isn’t the syntax for an object objectname: { properties of the object} ?