I’m just not sure why this isn’t meeting that one test where we have to create an array if the prop is tracks and there isn’t already a tracks property and then push the value. I would really appreciate the help and advice. I’ve tried just putting prop after the [id] and it doesn’t seem to work. Thanks in advance!!
function updateRecords(id, prop, value) {
var newArray = [];
if (prop == "tracks" && value != "") {
collection[id][prop].push(value);
} else if (prop == "artist" && value == "") {
delete collection[id].artist;
} else if (prop == "album" && value == "") {
delete collection[id].album;
} else if (prop == "tracks" && value == "") {
delete collection[id].tracks;
} else if (prop == "album") {
collection[id].album = value;
} else if (prop == "artist") {
collection[id].artist = value;
} else if (prop == "tracks" && collection[id].hasOwnProperty("tracks") == false) {
collection[id]["tracks"] = [];
collection[id]["tracks"].push(value);
} else {
return collection;
}
return collection;
}
awesome, but what happens if suddenly one wants to do updateRecords(1945, "release_year", 1978)? would your code work? can you make it work, whatever value is passed as prop?
} else {
collection[id][prop] = value; }
I really hadn’t thought about something like that. In fact looking at my code now I see that I could shorten it even more lol