Artist should not be set?

Tell us what’s happening:

I created this function all on my own and very proud of myself. However it took me hours to do it and I hope this is normal. So basically My function passes all of the tests except when it comes time to evaluate the empty string “”. I tested the function myself in google chrome developer console and artist is not being set. But yet I still get the below fails:

After updateRecords(2548, "artist", "") , artist should not be set
After updateRecords(2548, "tracks", "") , tracks should not be set

Can someone please shed some light on this as everything is working properly and I don’t get it and becoming frustrated.

Your code so far


// Setup
var collection = {
    "2548": {
      "album": "Slippery When Wet",
      "artist": "Bon Jovi",
      "tracks": [ 
        "Let It Rock", 
        "You Give Love a Bad Name" 
      ]
    },
    "2468": {
      "album": "1999",
      "artist": "Prince",
      "tracks": [ 
        "1999", 
        "Little Red Corvette" 
      ]
    },
    "1245": {
      "artist": "Robert Palmer",
      "tracks": [ ]
    },
    "5439": {
      "album": "ABBA Gold"
    }
};
// Keep a copy of the collection for tests
var collectionCopy = JSON.parse(JSON.stringify(collection));

// Only change code below this line
function updateRecords(id, prop, value) {

  var eval_track_prop = collection[id].hasOwnProperty("tracks");

  if(prop !== "tracks" && value !== ""){
    //update value for artist
    collection[id][prop] = value;
  } else if(prop === "tracks" && eval_track_prop === false){
    //Create 'tracks' property giving value empty array to store new tracks
    collection[id][prop] = [];
    //Push new track into the array
    collection[id][prop].push(value);
  } else if(prop === "tracks" && value !== ""){
    //Give property 'tracks' a new value
    collection[id][prop].push(value);
  } else {
    // delete the property and it's value
    delete collection[id].prop;
  }

  return collection;
};

// Alter values below to test your code
updateRecords(5439, "artist", "ABBA");

Your browser information:

User Agent is: Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:68.0) Gecko/20100101 Firefox/68.0.

Link to the challenge:
https://learn.freecodecamp.org/javascript-algorithms-and-data-structures/basic-javascript/record-collection

This is where the deletion of the property happens. But there is not a property called prop, I suggest you review difference between bracket and dot notation

Omg thank you so much for taking the time to look at this. I think I was looking at this for way too long and I can’t believe that’s all it was. I had that same exact line on a different if statement and fixed it but don’t know how I missed that one.