Record Collection - bug?

Hi all, after checking past posts regarding the same topic, I still fail to understand why I am getting error in the first checkpoint in my code.

First Checkpoint:

My Code:

function updateRecords(records, id, prop, value) {
  if(prop !== "tracks" && value !== ""){
    recordCollection[id][prop] = value;
  }else if(prop == "tracks" && !recordCollection[id].hasOwnProperty("tracks")){
    recordCollection[id].tracks = [];
  }else if(prop == "tracks" && value != ""){
  }else if(value == ""){
    delete recordCollection[id].prop;
  return records;

I did console.log(recordCollection) after updateRecords(recordCollection, 5439, ‘artist’, ‘ABBA’); and saw that my 5439’s artist does contain “ABBA”.

Here is the console.log you should get:

{ albumTitle: 'ABBA Gold', prop: 'ABBA' }

Notice how it’s not saying “artist”?
That’s because the dot-notation only applies to attributes. However “prop” is a variable and you have to access it the same way you did with id → wrap it in brackets.

Heya jagaya, i realized that mistake when i reread my post and fixed it but it still didnt quite work

Post edited accordingly

You are giving your function “records” as parameter. You have to use that within the function, instead of referring directly to recordCollection.

Why wouldnt directly referring to recordCollection work? The object is still modified. (is it because its specific to this challenge?)

Because the test-cases use their own object and not the one provided in the code-editor.

Reason being it violates the reusability-principle of the function. The way you wrote it, it would only work if the file to edit is available directly to the function. Also this way you can’t edit the object yourself and try cheating some tests.

1 Like

Ahh I see. Thanks for helping me out!

1 Like

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