// Setup
var collection = {
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(object, id, prop, value) {
if(prop!=="tracks" && value!==""){
object[id][prop]=value;
}
else if(prop==="tracks" && object[id].hasOwnProperty(prop)==false){
object[id][prop].push([value]);
}
else if(prop==="tracks" && value!==""){
objects[id][prop].push(value);
}
else if(value==="" &&object[id].hasOwnProperty(prop)==true){
delete object[id][prop];
}
return object;
}
updateRecords(collection, 5439, 'artist', 'ABBA');
Can anyone say the error in this plz??
struck up with 2 cases:
After updateRecords(collection, 1245, "tracks", "Addicted to Love")
, tracks
should have the string Addicted to Love
as the last element.
After updateRecords(collection, 2468, "tracks", "Free")
, tracks
should have the string 1999
as the first element.
Can u plz explain the how the object works too