Record Collection - what to they mean 'should not be set'? I have ignored this and left as is, I have also set the value to "" neither passes

Record Collection - what to they mean 'should not be set'? I have ignored this and left as is, I have also set the value to "" neither passes
0

#1

Tell us what’s happening:

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) {
  if (value === '') {
    console.log ("Nothing was set");
    collection[id][prop] = undefined;
    return collection;
  }

  else  if (prop === 'tracks' && collection[id].hasOwnProperty(prop) === false) {
    console.log("this hit test of has property - " + collection[id].hasOwnProperty('prop') + " prop "+ prop);
    collection[id][prop] = [];
    collection[id][prop] = [value];
    return collection;
  }

  else if (prop === 'tracks' && collection[id].hasOwnProperty(prop) === true) {
    console.log(" Push THIS!!! ")
    collection[id][prop].push(value);
    return collection;
  } 
  
  collection[id][prop] = value;
  return collection; 
  
} 
// Alter values below to test your code
updateRecords(5439, "artist", "ABBA");

Your browser information:

Your Browser User Agent is: Mozilla/5.0 (Macintosh; Intel Mac OS X 10_12_6) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/61.0.3163.100 Safari/537.36.

Link to the challenge:


#2

“Should not be set” means that it should not have anything assigned to it. You left off the “tell us what’s happening” section, so I can’t tell exactly what problem you’re experiencing. If this relates to the first if block though, you are setting collection[id][prop] to undefined.


#3

got it, “should not be set” = delete this property and value

:slight_smile:


#4

The only time you should delete a property/value is if value = ‘’.

Your function’s 2nd to last line is:

collection[id][prop] = value;

This line will always set the specific collection object’s property to value. This is causing a related problem, because you are setting properties even if the value is a blank string.