Record Collection struggle

Record Collection struggle
0

#1

Tell us what’s happening:
Here is my code for Record Collection challenger. I don’t understand why after running test, it’s still faul. Help me. Thanks in advance.

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

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

Your browser information:

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

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


#2

What if prop is “tracks” and value is not “”, but collection[id].tracks does not exist yet? Meaning, the object does not have a tracks array yet. You can not push to a non-existent array.


#3

As someone already mentioned read the questions being answered and just use that code first.

If prop isn’t “tracks” and value isn’t empty (""), update or set the value for that record album’s property.

Thats the sudo code above. How do we write that into javascript.