this is my answer :
function updateRecords(collection, id, prop, value) {
if(value === "")
{
delete collection[id][prop]
}
else if(prop != "tracks" && value != ""){
collection[id][prop] = value;
}
else if (prop === "tracks" ){
if(value == "Free")
{
collection[id][prop[0]] = [1999];
}
else{
collection[id][prop] = [value];
}
}
…
Top comments (1)
I have some questions for this - such as the function function updateRecords(object, id, prop, value) {
return object;
When was "object and prop and value" assigned or defined?
The object is named collection and I see it has properties and values although the ID's aren't named ID's but instead just numbers. How will the function relate the names id, prop, value and object back to the JSON?
Sorry but confused how the function call interacts with mapping the JSON to the names in the function. Thanks!
// 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) {
return object;
}
updateRecords(collection, 5439, 'artist', 'ABBA');