Tell us what’s happening:
Is there a way I can do this exercise by accessing the array, instead of doing in with If/Else statement? How would that be? I was trying to do it that way before I saw the solution.
You can see I also tried to use “var collection = delete [“collection”][“2548”][“artist”][“Bon Jovi”];” I tried all of different forms but it just didn’t work. Why? If there’s a way to do that how would that be? Is it possible? If not possible, why?
Here is the Exercise: https://learn.freecodecamp.org/javascript-algorithms-and-data-structures/basic-javascript/record-collection
Here’s the solution with If/Else statement: https://guide.freecodecamp.org/certifications/javascript-algorithms-and-data-structures/basic-javascript/record-collection/
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) {
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",
"artist": "ABBA",
"tracks": "Take a Chance on Me"
}
};
return collection
var collection = delete ["collection"]["2548"]["artist"]["Bon Jovi"];
}
// Alter values below to test your code
updateRecords(5439, "artist", "ABBA");
Your browser information:
User Agent is: Mozilla/5.0 (Windows NT 10.0) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/70.0.3538.77 Safari/537.36.
Link to the challenge:
https://learn.freecodecamp.org/javascript-algorithms-and-data-structures/basic-javascript/record-collection