Tell us what’s happening:
Forgive me if I am making an unusual request or seem difficult. I know this challenge is likely simpler than it seems to me, but I have spent two hours trying to solve and am losing sleep for it.
My code below is as far as I got on my own. I brought in the conditions as pseudocode to help, which they did a little. And those two hours include reviewing the solution, watching the video, and searching the forum, trying to get something to come together.
But it still makes no sense to me. A primary difficulty, I believe, is the language; I don’t clearly understand what I am being asked to do here.
By now, that’s not important. I don’t want the solution explained to me. I don’t want to know why the solution works.
I want to understand what I am supposed to have learned from this challenge. If I know that, then maybe this will make sense to me. But, until then, I cannot be satisfied simply moving on having learned nothing. Would you please help me?
Your code so far
// Setup
var collection = {
2548: {
albumTitle: 'Slippery When Wet',
artist: 'Bon Jovi',
tracks: ['Let It Rock', 'You Give Love a Bad Name']
},
2468: {
albumTitle: '1999',
artist: 'Prince',
tracks: ['1999', 'Little Red Corvette']
},
1245: {
artist: 'Robert Palmer',
tracks: []
},
5439: {
albumTitle: 'ABBA Gold'
}
};
// Only change code below this line
function updateRecords(object, id, prop, value) {
// If prop isn't tracks and value isn't an empty string, update or set that album's prop to value.
// If prop is tracks but the album doesn't have a tracks property, create an empty array and add value to it.
if(prop === 'tracks') {
object[id][prop] = [];
}
// If prop is tracks and value isn't an empty string, add value to the end of the album's existing tracks array.
// If value is an empty string, delete the given prop property from the album.
if(value === '') {
delete object[id][prop];
}
return object;
}
updateRecords(collection, 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/85.0.4183.121 Safari/537.36
.
Challenge: Record Collection
Link to the challenge: