Record Collection not creating new array

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:

Hello. Pay attention at these places

Thank you for your help!
Changing the first quoted part to “prop !== “tracks”” fixed my entire issue but now I’m not entirely sure why. I think I was accidentally checking if the prop was already in the records under the id, and since it wasn’t it would return true and add the value to the prop without an array. Is that correct?

this returns true all the time, because there are no properties with the value “tracks”

try records[id].tracks = value

This topic was automatically closed 182 days after the last reply. New replies are no longer allowed.