One of the indications of the challange is:
If
prop
is"tracks"
but the album doesn’t have a"tracks"
property, create an empty array before adding the new value to the album’s corresponding property.
So you will test if “prop” is "tracks"with:
else if (prop === "tracks")
Now you will use an interesting feature of Javascript, within an assignment you can have an ‘or’ operator, if the left value fails(0, empty array or string, false or empty object), it will assign the right one:
collection[id][prop] = collection[id][prop] || [];
For example:
let A = 0;
let B = A || 1;
console.log(B); //1
So you will assign collection[id][prop] to itself but if it doesn’t exist it will create one empty array. It is shorter than write and if-else statement.