hi everyone! i’m stuck in the record collection challenge from the basic javascript challenges. i was looking the solutions made by other users but i still don’t know how to set the new properties for the record, the modifications that the challenge is asking for. i’ve configured (with SOME help) this code for the first part, when we have to follow the rules like “if prop is an empty string…” and so on.
function updateRecords(object, id, prop, value) {
if (prop !== 'tracks' && value !== "") {
object[id][prop] = value;
}
else if (prop === 'tracks' && !object[id].hasOwnProperty("tracks")) {
object[id][prop] = [value];
}
else if (prop === tracks && value !== "") {
object[id][prop].push(value);
}
else if (value === "") {
delete object[id][prop];
}
return object;
}
BUT i can’t find help about the second part, like, p.e. "After updateRecords(collection, 5439, "artist", "ABBA")
, artist
should be ABBA
"
I’ve tried to code this using my intuition (?, but obviously it doesn’t work since I don’t know exactly what is the syntax i should use
updateRecords(collection, 5439, ‘artist’, ‘ABBA’); // This line is previously offered as an example, but I don’t understand if the other modifications should respect the same structure, since it doesn’t work
updateRecords(collection, 5439, 'tracks'.push(["Take a Chance on Me"]);
updateRecords(collection, 2548, 'artist' = "");
updateRecords(collection, 1245, 'tracks', collection.tracks.push(["Addicted to Love"]);
updateRecords(collection, 2468, 'tracks'.unshift([1999]);
updateRecords(collection, 2548, 'tracks' = "");
updateRecords (collection, 1245, 'albumTitle' = 'Riptide');
I appreciate any help or suggestions, I am a little lost code-beginner. xoxo