Tell us what’s happening:
I am getting the push is not defined error for this challenge. I have tried searching for a sollution, and it seemed people were saying that it assumes that my collection has a prop of ‘tracks’
But when going through my code I am checking if it has a prop of tracks
else if ( prop === "tracks" && value !== "") {
been looking at this sideways and not getting any further, and am so confused about why it’s not working. please someone help me.
I added comments through my code to explain my thought process while writing the code, hope it helps.
Thanks
Alex
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"
}
};
// 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) {
//find if prop is not tracks and value is not empty
if (prop !== "tracks" && value !== "") {
// if true then add value to prop
collection[id][prop] = value;
//if false then find out if prop is tracks and value is not empty
} else if ( prop === "tracks" && value !== "") {
//if true check if tracks has an empty value
if (collection[id].tracks === "") {
//if tracks is empty then add value inside a array
collection[id].tracks[value];
//if tracks has an array push value onto end of array
} else
collection[id].tracks.push(value);
//if value is empty then delete prop
} else if (value === "") {
delete collection[id][prop];
}
return collection;
}
// Alter values below to test your code
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/76.0.3809.132 Safari/537.36
.
Link to the challenge:
https://learn.freecodecamp.org/javascript-algorithms-and-data-structures/basic-javascript/record-collection