Tell us what’s happening:
Describe your issue in detail here.
Hi, I’m working on the assignment Record Collection and I’m having issues with getting tracks to be added as arrays or within arrays.
As far as I can tell I have written my code similarly to the code in the first Solution found here, including how I put value in array brackets.
I’m not sure why this isn’t working correctly or how I can fix it.
I have also tried making an empty array and then .push the value in the array like so:
records[id][prop] = ;
records[id][prop].push(value);
but this still does not create an array around the track title in the console.log()
**Your code so far**
// Setup
const 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 (records[id][prop] !== "tracks" && value !== "") {
records[id][prop] = value;
} else if (prop === "tracks" && records[id].hasOwnProperty("tracks") === False) {
records[id][prop] = [value];
} else if (prop === "tracks" && value != "") {
records[id][prop].push(value);
} else if (value === "") {
delete records[id][prop];
}
return records;
}
console.log(updateRecords(recordCollection, 5439, "tracks", 'Take a Chance on Me'));
console.log returns ‘5439’: { albumTitle: ‘ABBA Gold’, tracks: ‘Take a Chance on Me’ } showing the title of the track has not been added within an array.
**Your browser information:**
User Agent is: Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:101.0) Gecko/20100101 Firefox/101.0
Challenge: Record Collection
Link to the challenge: