the collection object is initialised in the code . I don’t see the initialisation part in your code (initialising a variable means giving it a value in the same line it is declared). You are actually missing the part in which the object is stored in the variable, if that is your whole code
if you reset the code you should see it whole
It is great that you solved the challenge, but instead of posting your full working solution, it is best to stay focused on answering the original poster’s question(s) and help guide them with hints and suggestions to solve their own issues with the challenge.
We are trying to cut back on the number of spoiler solutions found on the forum and instead focus on helping other campers with their questions and definitely not posting full working solutions.
Also, please do not revive old threads simply for the purpose of posting solutions.
I was also facing the problem in this step and even after i see the solution i could not get the right answer thats why i wrote the solutio. But as per your advice i already edit that and instead of writing the whole solution i wrote the steps to be follow, i hope this will help
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")){
collection[i].tracks.push(value);
}
else {
collection[i].tracks = value;
}
}
else {
collection[i][prop] = value;
}
}
}
return collection;
}
// Alter values below to test your code
console.log(updateRecords(5439, "artist", "ABBA"));
It is great that you solved the challenge, but instead of posting your full working solution, it is best to stay focused on answering the original poster’s question(s) and help guide them with hints and suggestions to solve their own issues with the challenge.
We are trying to cut back on the number of spoiler solutions found on the forum and instead focus on helping other campers with their questions and definitely not posting full working solutions.