Tell us what’s happening:
Hello, good afternoon …
I am trying to perform this JavaScript certification exercise in which I have a list of objects in which the first thing I do is check that the field to change is different from tracks (that is, artist) and that the value is not null , otherwise if it is tracks then I verify that this field exists in the list in order to create an empty arrangement referring to it and with its value, then it is verified that value is not an empty string and I insert it at the end of the list , and if it is empty, this property is eliminated. I think I must have the error in the empty arrangement … I don’t know … it’s where I more or less feel lost
Your code so far
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'
}
};
function updateRecords(object, id, prop, value) {
if (prop!=='tracks' && value!=="") {
object[id][prop]=value;
} else if (prop==="tracks" && object[id].hasOwnProperty("tracks")==="false") {
object[id][prop]=[value];
} else if (prop==="tracks" && value!=="" && object[id][prop].hasOwnProperty) {
object[id][prop].push(value);
} else if (value==="") {
delete object[id][prop];
}
return object;
}