Tell us what’s happening:
The reason given for the failure of my code is, “Cannot read property ‘pop’ of undefined”. I didn’t trigger the pop command in this exercise and `I’m at a loss regarding what the ‘pop’ refers to.
Could someone kindly explain what is happening here and where my error is coming from?
I am taking a break now and will pick up any responses later in the day. Many thanks in advance for coming to my aid.
// 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" && value !== ""){
if (collection[id][prop]){
collection[id][prop].push(value);
}
}
else if (value === "") {
delete collection[id][prop];
}
return collection;
};
// Alter values below to test your code
updateRecords(5439, "artist", "ABBA");
**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" && value !== ""){
if (collection[id][prop]){
collection[id][prop].push(value);
}
}
else if (value === "") {
delete collection[id][prop];
}
return collection;
};
// Alter values below to test your code
updateRecords(5439, "artist", "ABBA");
// running tests
Cannot read property 'pop' of undefined
// tests completed
You may refer back to [Manipulating Complex Objects](https://learn.freecodecamp.org/javascript-algorithms-and-data-structures/basic-javascript/manipulating-complex-objects) Introducing JavaScript Object Notation (JSON) for a refresher.
Run the TestsReset All Code[Get a hint](https://guide.freecodecamp.org/certifications/javascript-algorithms-and-data-structures/basic-javascript/record-collection)Ask for help
Passed
After `updateRecords(5439, "artist", "ABBA")` , `artist` should be `"ABBA"`
After `updateRecords(5439, "tracks", "Take a Chance on Me")` , `tracks` should have `"Take a Chance on Me"` as the last element.
Passed
After `updateRecords(2548, "artist", "")` , `artist` should not be set
Passed
After `updateRecords(1245, "tracks", "Addicted to Love")` , `tracks` should have `"Addicted to Love"` as the last element.
Passed
After `updateRecords(2468, "tracks", "Free")` , `tracks` should have `"1999"` as the first element.
Passed
After `updateRecords(2548, "tracks", "")` , `tracks` should not be set
Passed
After `updateRecords(1245, "album", "Riptide")` , `album` should be `"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/75.0.3770.142 Safari/537.36
.
Link to the challenge:
https://learn.freecodecamp.org/javascript-algorithms-and-data-structures/basic-javascript/record-collection