Alright so I passed this challenge yesterday and have reset it 6-7 times to do it over again and pass again. I really want to fully grasp this theory, so I don’t mind spending a couple days studying it. So my question is the positioning of the if/else, else if statements. Originally I placed the “delete collection” segment at the bottom of the code and followed instructions 1-3 at the top and it passed. Then I placed the delete at the top and put one of the push statements on the bottom as you can see here. It passed. Then I tried putting the statement with the empty array and push at the bottom and it everything failed for one condition. Then I tried setting the value at the end as well and it failed two conditions. Can someone explain in more detail whats going on, I know its the way the statements are structured.
Thanks!!
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];
} else if (prop != "tracks" && value != "") {
collection[id][prop] = value;
} else if (prop == "tracks" && collection[id].hasOwnProperty(prop)==false) {
collection[id][prop] = [];
collection[id][prop].push(value);
} else {
if (prop == "tracks" && value != "") {
collection[id][prop].push(value);
}
}
return collection;
}
updateRecords(5439, "artist", "ABBA");
Your browser information:
User Agent is: Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/83.0.4103.97 Safari/537.36
.
Challenge: Record Collection
Link to the challenge: