Okay, thanks for explaining that, but before using switch I tried with if and else if statements using the same mentioned cases and still have some problem with my code…Could you comment on the cases I wrote in my code?
remember what’s the main difference between dot notation and bracket notation
after you solve that, there is a small logic issue for an edge case… what happens with updateRecords(2456, "tracks", "")? (consider that the 2456 is a valid id)
Yeah, I got that and this fixes some errors but still show these 2 errors:
// running tests
After updateRecords(2468, "tracks", "Free"), tracks should have "1999" as the first element.
After updateRecords(2548, "tracks", ""), tracks should not be set
// tests completed
function updateRecords(id, prop, value) {
if (prop !== "tracks" && value !== ""){
collection[id][prop] = value;
}
else if (prop === "tracks" && !collection.hasOwnProperty("tracks")){
collection[id].tracks = [];
collection[id].tracks.push(value);
}
else if (prop === "tracks" && value !== ""){
collection[id].tracks.push(value);
}
else if (value === ""){
delete collection[id][prop];
}
return collection;
}
Sorry for this mistake.
It is “tracks” not “value”.
But I didn’t get you, I think it should always evaluate to false since it is the case where the album doesn’t have a “tracks” property!!!
I deal with every if and (else if) statement as completely independent case just like switch statement, and not like if and (else) statements… Is this right?