Tell us what’s happening:
I looked up the hints for this exercise and trying to understand the meaning / what the following line does
collection[id][prop] = collection[id][prop] || ;
the code won’t work without it but not sure why it’s needed.
Your 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 (value === "") {
delete collection[id][prop];
console.log(collection[id]);
} else if (prop === "tracks") {
collection[id][prop] = collection[id][prop] || [];
collection[id][prop].push(value);
}
return collection;
}
updateRecords(5439, "artist", "ABBA");
updateRecords(5439, "tracks", "Take a Chance on Me");
updateRecords(2548, "artist", "");
updateRecords(1245, "tracks", "Addicted to Love");
updateRecords(2468, "tracks", "Free");
updateRecords(2548, "tracks", "");
updateRecords(1245, "album", "Riptide");
Your browser information:
User Agent is: Mozilla/5.0 (Macintosh; Intel Mac OS X 10_12_6) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/81.0.4044.122 Safari/537.36
.
Challenge: Record Collection
Link to the challenge: