Record Collection cannot pass this why so

Tell us what’s happening:

function updateRecords(id, prop, value) {
if (prop == “tracks” && !collection[id].hasOwnProperty[(“tracks”)]){
collection[id][prop]=[].push(value);
}
else if (prop == “tracks” && value!==""){
collection[id][prop]= value.push(value);
}
else if (value ===""){
delete collection[id][prop];
}
return collection;
}

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

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

```why am i not passing this test

**Your browser information:**

User Agent is: <code>Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/72.0.3626.121 Safari/537.36</code>.

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

You should check for prop && value.
Your first if condition should be (prop !== 'tracks' && value !== '') then set the new value.

You second condition is ok, but the logic is off.
You should check if collection[id] has property tracks after that.
If false, create an empty array.
and then push value to collection[id][prop].

You are also totally missing conditions for when prop isn’t "tracks" and value is not an empty string - right now nothing is executed in that situation

Thanks for the suggestion, I finally managed to pass this test by doing the following:

// Only change code below this line
function updateRecords(id, prop, value) {
if (prop !== “tracks” && value !==""){

 collection[id][prop]= value;

}
if (prop == “tracks” && collection[id].hasOwnProperty(prop)== false){
collection[id][prop]= [];
collection[id][prop]= [value];
}
if (prop == “tracks” && value !== “”){
collection[id][prop].push(value);
}
else if (value ==""){
delete collection[id][prop];
}

return collection;
}

Thanks, I passed this time with the following:
// Only change code below this line
function updateRecords(id, prop, value) {
if (prop !== “tracks” && value !==""){

 collection[id][prop]= value;

}
if (prop == “tracks” && collection[id].hasOwnProperty(prop)== false){
collection[id][prop]= [];
collection[id][prop]= [value];
}
if (prop == “tracks” && value !== “”){
collection[id][prop].push(value);
}
else if (value ==""){
delete collection[id][prop];
}

return collection;
}

The result of these two, if the object doesn’t have the tracks property, is:
tracks: [value, value]

Oh , so was my result wrong then?Wonder how I ‘passed’ the test then

Because the tests can’t check for everything, the only way to check if your code is right is to check the output manually and see if it is the expected output

Anyway for the above you have a few simple corrections you could do:
Way one: make it an if ... else if so that only one of the two executes
Way two: make the first statement just create an empty array, so that it will be filled by the second statement