Record collection(fcc)

The code so far but too confused.
/

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

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

I’ve edited your post for readability. When you enter a code block into a forum post, please precede it with a separate line of three backticks and follow it with a separate line of three backticks to make easier to read.

See this post to find the backtick on your keyboard. The “preformatted text” tool in the editor (</>) will also add backticks around text.

Note: Backticks are not single quotes.

markdown_Forums


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

The else if block will never execute. It is only checked if prop === "tracks" is false, but one of its conditions is that prop === "tracks" is true.

This is the code I made which is modified again.

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

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

This sintax doesn’t work the way you think
Whatever is inside the brackets is evaluated before accessing the property, what’s happening is that you are trying to access a property called undefined (because that is what prop[value] evaluates to) inside the collection object

Also, remember that each item in the collection has an id
Example

collection = {
   1234: {
      "title": "blah",
      "author": "bleh"
   },
   2345: {
       "title": "bluh",
       "author": "bloh"
   }
}

You have collection collection
With collection[1234] you get the inner object. With collection[1234]["title"] you get "blah"
And if you do collection[1234]["title"] = "nope", using the assignment operator =, next time you access that property collection[1234]["title"] you get the "nope" value

You also can’t do this:

You may want to review how push work…

I finally tried somehow but still not getting it

// Setup
var collection = {
    "2548": {
      "album": "",
      "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 === ""){
     delete collection[id][prop];
   }
  
  else if(prop === "tracks"){
    collection[id][prop] = collection[id][prop] || [];
    
  }
  else if(prop ==="tracks" && value !== ""){
    collection[id][prop].push(value);  
  }
  return collection;
}

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

This are mutually exclusive, so if prop is "tracks" only the first one will execute. you will end with the original value or an empty array and stop

Also, you are missing when prop is not "tracks"

Yeah I was wrong,thanks for replying but I have no other way

What do you mean you have no other way? And to do what?