I’m trying to solve this example. I even used ‘Get a Hint’ but I still have problem running it. The test result says:
After updateRecords(collection, 2468, “tracks”, “Free”), tracks should have the string 1999 as the first element.
After updateRecords(collection, 2548, “tracks”, “”), tracks should not be set.
This is my code:
function updateRecords(object, id, prop, value) {
if (prop !== "tracks" && value !== ""){
object[id][prop] = value;
} else if (prop === "tracks" && object.hasOwnProperty("tracks") === false) {
object[id][prop] = [value];
} else if (prop === "tracks" && value !== ""){
object[id][prop].push(value);
} else if (value === "") {
delete object[id][prop];
}
return object;
}
updateRecords(collection, 5439, 'artist', 'ABBA');
Thanks for your help!
**Your browser information:**
User Agent is: Mozilla/5.0 (Windows NT 6.1; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/89.0.4389.114 Safari/537.36
.
Challenge: Record Collection
Link to the challenge: