Challenge Record Collection JS

Tell us what’s happening:
Ok, so with the code that you can see below, the first piece (you are going to have to scroll all the way down for the second bit of code), the following challenge milestones are met and not met:

After updateRecords(collection, 5439, "artist", "ABBA") , artist should be the string ABBA

Passed

After updateRecords(collection, 5439, "tracks", "Take a Chance on Me") , tracks should have the string Take a Chance on Me as the last element.

Passed

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

Passed

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

Failed
After updateRecords(collection, 2468, "tracks", "Free") , tracks should have the string 1999 as the first element.

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

Passed

After updateRecords(collection, 1245, "albumTitle", "Riptide") , albumTitle should be the string Riptide

HOWEVER!!

If I change the “!== true” part of my:

else if(prop === “tracks” && object.hasOwnProperty(“tracks”) !== true) {
object[id][prop] = [value];

statement, to just:

else if(prop === “tracks” && object.hasOwnProperty(“tracks”)) {
object[id][prop] = [value];

then I fail a different set and pass a different set of challenges??
I suppose what I am trying to ask is how can I be half right on both occaisions? I can figure out how to pass this challenge with a bit of trial and error but I feel that I lack an understanding of what is going on…

Thank you in advance to anyone who answers. All the best :smiley:

  **Your code so far**

// Setup
var collection = {
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(object, id, prop, value) {
if(prop !== "tracks" && value !== "") {
  object[id][prop] = value;
}

else if(prop === "tracks" && object.hasOwnProperty("tracks") !== true) {
  object[id][prop] = [value];

}

else if(prop === "tracks" && value !== "") {
  object[id][prop].push(value);
}

else if(value === "") {
  delete object[id][prop];
}
return object;
}

updateRecords(collection, 5439, 'artist', 'ABBA');
  **Your browser information:**

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

Challenge: Record Collection

Link to the challenge:

A post was merged into an existing topic: FCC JavaScript Course - Record Collection

Please do not create duplicate topics for the same challenge/project question(s). This duplicate topic has been unlisted.

Thank you.