Tell us what’s happening:
Hi, I am at the Record collection challenge and am trying to avoid spoilers, so I am posting to see if what I have done so far (from the code I have entered) will work to complete the first three requirements. There are 5 requirements total, I will list my issues starting with the first. I am very new to JS and am still trying to get comfortable with these challenges that tbh are pretty difficult. I have reviewed the lessons a few times regarding objects, but whats different with this challenge is that a lot of it seems to take place from within a function, not just outside of one, which is what is throwing me off.
1st requirement( * Your function must always return the entire object.): This doesnt seem to be an issue since the return is already set for the object to be returned. I don’t have to do anything to this, right?
2nd requirement (If prop isn’t tracks and value isn’t an empty string, update or set that album’s prop to value.): For this, I added an if statement as follows:
if (prop != “tracks” && value != “”){
prop = value;
}
is this correct? or am I going in the wrong direction? Should I create two variables for prop and value in this function and then pass those along instead? I feel like this the way I already have it is enough.
3rd requirement(If prop is tracks but the album doesn’t have a tracks property, create an empty array and add value to it.): I am stuck on adding the Track value to the id 5439. I know I can add this the way I have it written, but it sounds like the challenge wants me to add this stuff through the inside of the function. It also seems like it wants me to write a more generalized operation that could apply to any given id, not just id 5439. I am just not aware how to do this from within a function instead of outside. Is that correct? If so, how do I manipulate the properties of the object from within the function? The lessons that seem to cover this all seem to do with doing this stuff from outside of a function so it seems that even if I try to assign a variable to the property for track from within the function, I would need to still be specific to the track id 5439.
Any help is really appreciated!
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
collection[5439].artist = "ABBA";
collection[5439].tracks = ["dancing queen"];
console.log(collection[5439]);
function updateRecords(object, id, prop, value) {
// 1st if statement
if (prop != "tracks" && value != ""){
prop = value;
}
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/87.0.4280.141 Safari/537.36.
Challenge: Record Collection
Link to the challenge:
