Record Collection problem

Record Collection problem
0.0 0

#1

Tell us what’s happening:
one test case(mentioned while calling) is not passing

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

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

#2

In the case of updateRecords(5439, "tracks", "Take a Chance on Me")

 if(!collection[id][prop])
    collection[id][prop]=value;

is executing. That means that tracks is a string instead of an array.


#3

if i am making it as array…then a differernt test case is creating issue updateRecords(5439, "artist", "ABBA");

if(!collection[id][prop])
    collection[id][prop]=[value];

#4

tracks is a special case, so you’ll want to treat it differently than other possible values of prop.


#5

oh ok ok! thanx, i got it now


#6

i have posted two more doubts please have a look on them


#7

Where?


#9

https://forum.freecodecamp.org/t/arguments-optional-problem/192380 here i had asked


#10

Can I use "collection.id[prop]’ instead of ‘collection[id][prop]’?


#11

Not if id is a variable.