Record Collection Failing All Tests

Tell us what’s happening:
Every test I have keeps failing on the record collection challenge. I went as far as the hint page and even copied the solution and everything is failing. I have finished other challenges before and after and this is the only one giving me issues. What in the world am I missing?

  **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"
}
};

// Only change code below this line
function updateRecords(id, prop, value) {
if (prop !== 'tracks' && value !== ""){
  collection[id][prop] = value;
}
else if (prop === "tracks" && !collection[id].hasOwnProperty("tracks")){
  collection[id][prop] =[]; 
}
else if (prop === "tracks" && value != ""){
  collection[id][prop].push(value);
}
else if(value === ""){
  delete collection[id][prop];
}
return collection;
}


  **Your browser information:**

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

Challenge: Record Collection

Link to the challenge:

Looks like you have modified the function deckaration itself.

It takes 4 arguments: collection, id , prop, value. You have only 3.

So it should be
function updateRecords(collection, id, prop, value){
…your code here…
}

So weird, even when I reset the code I only have the same three variables. I will try adding collection to it. Thank you!

So I tried that and I tried copying the entire solution, even the setup code, and everything fails. I have completed the challenges after this one as well and this is the only one not passing for me.

You changed the function signature. I’d imagine that you looked at old solutions and tried to replicate them.

The challenges get updates from time to time, so trying to replicate the old solutions of others will sometimes lead you astray. This one was changed a fairly long time ago.

I’d reset the challenge and use the correct function signature.

Here is the correct function signature

function updateRecords(records, id, prop, value) {
1 Like

Thanks Jeremy, even when I reset the code it’s just (id,prop,value). Here is my current code failing all tasks.

// 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"
  }
};

// Only change de below this line
function updateRecords(records, id, prop, value) {
  if (prop !== 'tracks' && value !== "") {
    records[id][prop] = value
  } else if (prop === 'tracks' && records[id].hasOwnProperty('tracks') === false) {
    records[id][prop] = [value]
  } else if (prop === 'tracks' && value !== "") {
    records[id][prop].push(value)
  } else if (value === "") {
    delete records[id][prop]
  }
  return records;
}

updateRecords(collection,5439, "artist", "ABBA");

This is the base code when I ‘Reset All Code’. The function signature only contains (id, prop, value). I have tried my own solution which I had working in my editor, I have tried the solution on FreeCodeCamp and I have also tried solutions I have found elsewhere. This is the only challenge that I’m having issues with. I understand the logic of the program as well.

// 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"
  }
};

// Only change code below this line
function updateRecords(id, prop, value) {


  return collection;
}

updateRecords(5439, "artist", "ABBA");

I have no idea how you would get that as the starter code since we haven’t used that for a long time.

Somehow you are receiving an old version of the challenge. I don’t know what could possibly cause that.

1 Like

Here’s the current starter code:

// Setup
const recordCollection = {
  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(records, id, prop, value) {
  return records;
}

updateRecords(recordCollection, 5439, 'artist', 'ABBA');
3 Likes

Thank you, I’ll give it a shot.

This topic was automatically closed 182 days after the last reply. New replies are no longer allowed.