Tell us what’s happening:
Hi all,
Having completed the Record Collection challenge (which was strangely satisfying), I then went on to try to use a console.log to print the output to the console. I have included my code at the end of the challenge, which I thought would be as simple as entering 'console.log(updateRecords(5439, “artist”, “ABBA”)); '. However, this only prints ‘object Object’ to the console. I’ve tried a host of variations, some of which result in no return at all. I’ve been through various previous lessons on how to access nested object and nested arrays etc, but I haven’t been able to get this to print to the console.
I’m sure this is going to be painfully simple, so I’m ready to be humiliated
**Your code so far**
```js
// 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"
}
};
// 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) {
if (prop != "tracks" && value != "") {
collection[id][prop] = value;
} else if (prop == "tracks" && collection[id].hasOwnProperty("tracks") != true) {
collection[id].tracks = [(value)];
} else if (prop == "tracks" && value != "") {
collection[id].tracks.push(value);
} else if (value == "") {
delete collection[id][prop];
}
return collection;
}
// Alter values below to test your code
console.log(updateRecords(5439, "artist", "ABBA"));
Your browser information:
User Agent is: Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:67.0) Gecko/20100101 Firefox/67.0
.
Link to the challenge:
https://learn.freecodecamp.org/javascript-algorithms-and-data-structures/basic-javascript/record-collection/