Record Collection (empty array point)

Tell us what’s happening:
Hey guys. I’ve been struggling for a few hours now with this exercise. Managed to pass every item in the check list except for this one:

After updateRecords(recordCollection, 1245, "tracks", "Addicted to Love"), tracks should have the string Addicted to Love as the last element.

This bit is relevant, I promise:

If prop is tracks but the album doesn’t have a tracks property, create an empty array and add value to it.

Now, in a literal sense, doesn’t the tracks property already exist as an empty array? Am I confusing the definition of “property”? Isn’t “property” an equivalent to “key” when thinking “assignations” as key: value (values are assigned to keys).
Idk if my (hideous) code does exactly what it’s stated (create an empty array and add value to it) but that’s literally what I’m trying to do here.
Anyways, I’d also love any suggestions you may have that are beyond the scope of this particular doubt. Thanks a lot!

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 (prop != "tracks" && value != ""){
    records[id][prop] = value;
  } else if (prop == "tracks" && records[id].hasOwnProperty("tracks") == false) {
    records[id][prop] = [];
  } else if (prop == "tracks" && value != "") {
  } else if (value == "") {
  delete records[id][prop];  
  return records;

//updateRecords(recordCollection, 5439, 'artist', 'ABBA');
//updateRecords(recordCollection, 2548, "artist", "");
updateRecords(recordCollection, 1245, "tracks", "Addicted to Love")

Challenge: Record Collection

Link to the challenge:

I’d take a real close look at your third if statement and verify that it is doing what you want it to do.

Omg I’m dumb. So I’ve been confusing the ifs all this time lol. Thanks for pointing that out.
Solved it with:

Thank you!

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