Record Collection Help! (looked through other topics and vids)

Tell us what’s happening:

I don’t understand what I’m doing with this challenge?

I’ve taken a look through other topics on here and on StackOverflow and none of the code provided will pass the tests.
I even followed freeCodeCamp’s YouTube video and copied it exactly and that doesn’t even work? (screenshot below)

Can someone help and dumb it down for me a little?
I swear if there’s just a silly typo I’m gonna go mad haha…

Thank you

Your code so far


// Setup
var collection = {
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
// A copy of the collection object is used for the tests.
var collectionCopy = JSON.parse(JSON.stringify(collection));

function updateRecords(id, prop, value) {
if (value === "") {
  delete collection[id][prop];
} else if (prop === "tracks") {
  collection[id][prop] = collection[id][prop] || [];
  collection[id][prop].push(value);
} else {
  collection[id][prop] = value;
}

return collection;
}

updateRecords(collection, 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/86.0.4240.75 Safari/537.36.

Challenge: Record Collection

Link to the challenge:

reset your code and note that the function has changed since the video was recorded: the function signature has four parameters, and you can’t change that

2 Likes

I now have:

function updateRecords(object, id, prop, value)

Which is what it was before. In super simple terms, why is this like this?

I now have these errors only:

// running tests
After updateRecords(collection, 2548, "artist", ""), artist should not be set
After updateRecords(collection, 2548, "tracks", ""), tracks should not be set
// tests completed

Why is this when I have:

  if (value === "") {
    delete collection[id][prop];

Thanks!

You should never reference collection in your solution.

1 Like

can you eLI5?

if I don’t reference collection what do I write in order to refer to the collection of records?

all answers I’ve seen include collection[id][prop] etc in the solution, how does this work/not work?

EDIT:
Sorry, brainfart.
object refers to collection. so it’s object[id][prop] not collection[id][prop]

This now works!

Code for anyone else who is struggling:

// Only change code below this line
function updateRecords(object, id, prop, value) {
  if (value === '') {delete object[id][prop];}
  else if (prop === 'tracks') {
    object[id][prop] = object[id][prop] || [];
    object[id][prop].push(value);
  } else {
    object[id][prop] = value;
  }

  return object;}

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

Thanks all!