Tell us what’s happening:
Describe your issue in detail here.
trying to solve the second problem
- If
prop
istracks
but the album doesn’t have atracks
property, create an empty array and addvalue
to it.
and here is my current code for it
else if (prop === “tracks” && !records[id].hasOwnProperty(“tracks”))
can anyone give me any hints or suggestions in the right direction? thanks
Your code so far
// Setup
var recordCollection = {
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(records, 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 !== "tracks" && value !== "") {
records[id][prop] = value;
//If prop is tracks but the album doesn't have a tracks property, create an empty array and add value to it.
} else if (prop === "tracks" && !records[id].hasOwnProperty("tracks")) {
//If prop is tracks and value isn't an empty string, add value to the end of the album's existing tracks array.
} else if (prop === "tracks" && value !== "") {
records[id][prop].push(value);
//If value is an empty string, delete the given prop property from the album.
} else if (value === "") {
delete records[id][prop];
}
return records;
}
updateRecords(recordCollection, 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/92.0.4515.159 Safari/537.36
Challenge: Record Collection
Link to the challenge: