Please forgive me I’m a newbie…
I don’t know if it’s me or is this challenge written in a way where it’s hard to interpret what 's been asked. I’m not understanding. Is it’s asking to update the VAR COLLECTION, because it ask to update or set the value
for that record album’s property.
Isn’t the album property album, artist and tracks?
See below…
Write a function which takes an album’s id
(like 2548
), a property prop
(like "artist"
or "tracks"
), and a value
(like "Addicted to Love"
) to modify the data in this collection.
If prop
isn’t "tracks"
and value
isn’t empty ( ""
), update or set the value
for that record album’s property.
The code below is from the hint. I have been practicing with it. I’m stuck here trying to get a better understanding. I don’t want to move on until I do. I have been working on it for a while. I understand what the code is doing, but I don’t understand some of the wording.
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"
}
};
// Only change code below this line
function updateRecords(id, prop, value)
if (prop === "tracks" && value !== "") {
collection[id][prop].push(value);
}
else {
collection[id][prop]=[value];
} else if (value !== "") {
collection[id][prop] = value;
} else {
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; rv:73.0) Gecko/20100101 Firefox/73.0
.
Challenge: Record Collection
Link to the challenge:
https://www.freecodecamp.org/learn/javascript-algorithms-and-data-structures/basic-javascript/record-collection