Record Collection Challenge#

Tell us what’s happening:
Hello guys, i was doing this challenge and really tried to follow up the conditions given but still not getting it right, getting 4/7.
please help and i think my problem is with the third condition.Happy CODE…

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) {
  // First condition
  if(collection[id][prop] !== "tracks" && value !== ""){
    collection[id][prop] = value

    // Second condition
  }else if(collection[id][prop] === "tracks" ){
    if(!(collection[id][prop].hasOwnProperty(prop))){
      collection[id][prop] = value
    }
     
     //Third condition
  }else if(collection[id][prop] === "tracks" && value !== ""){
     collection[id][prop].push( value) 

     //Fourth condition
  }else if(value === ""){
    delete collection[id][prop]
  }
  return collection;
}

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

Your browser information:

User Agent is: Mozilla/5.0 (Windows NT 10.0; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/70.0.3538.102 Safari/537.36 OPR/57.0.3098.106 (Edition Campaign 34).

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

This may help ~~>

http://forum.freecodecamp.org/t/alternate-solution-for-record-collection-on-fccs-yt-channel/249659?u=connectextend

Your problem starts with the first one. What tests you pass, you pass accidentally.

collection[id][prop] will never equal “tracks” because tracks is a prop.

for instance, if id is 2548 and prop is "tracks", collection[id][prop] will be ["Let It Rock", You Give Love a Bad Name"]

1 Like

What is collection[id][prop] ? Can it ever by equal to "tracks"?

Maybe you want to check what prop is instead

1 Like