I am working through the freeCodeCamp tutorial for Javascript, and have been working through the Record Collection assignment. I'm trying the write it differently than is presented, but despite looking through the past tutorials and searching online, I can't understand why my code is not appending the property "artist" to the 5439 object.
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"
}
};
// Keep a copy of the collection for tests
var collectionCopy = JSON.parse(JSON.stringify(collection));
// Only change code below this line
function updateRecords(id, prop, value) {
for (var i in collection){
if (i == id){
if (value == ""){
delete collection.i.prop;
}
else if (prop == "tracks" && value !== ""){
if (collections.hasOwnProperty("tracks")){
i.tracks.push(value);
}
else {
i["tracks"] = value;
}
}
else {
i.prop = value;
}
}
}
return collection;
}
// Alter values below to test your code
console.log(updateRecords(5439, "artist", "ABBA"));
I've looked through the online tutorials and it looks like I am including it properly. I've tried bracket notation as well and nothing has worked but when I debug my code and print the result, nothing is added. Am I just not accessing the object at all?