I think my code is doing okay but there is this tests that is giving an error and I tried to debug but I can’t help it anymore. Any help would be appreciated!
My code so far
// Setup
var collection = {
2548: {
album: "Slippery When Wet",
artist: "Bon Jovi",
tracks: [
"Let It Rock",
"You Give Love a Bad Name"
]
},
2468: {
album: "1999",
artist: "Prince",
tracks: [
"1999",
"Little Red Corvette"
]
},
1245: {
artist: "Robert Palmer",
tracks: [ ]
},
5439: {
album: "ABBA Gold"
}
};
// Only change code below this line
function updateRecords(id, prop, value) {
if (prop != "tracks" && value != "") {
// console.log("inside first conditional")
collection[id][prop] = value;
}
if (prop === "tracks") {
// console.log("inside second conditional")
if (collection[id].tracks == undefined) {
collection[id].tracks = []
}
if (value != "") {
collection[id].tracks.push(value)
} else {
delete collection[id][prop];
}
}
return collection;
}
updateRecords(5439, "artist", "ABBA");
// running tests After
updateRecords(2548, "artist", "") , artist should not be set
// tests completed
Challenge: Record Collection
Link to the challenge: