Record Collection Function returned every bullet in the checklist as incorrect

Tell us what’s happening:
UPDATE - Never mind I figured it out. Turn outs the return records bit was in the wrong spot. I’m going to leave this here though in case anyone else makes the same mistake. HOWEVER this bullet in the checklist is still not being met - After "updateRecords(recordCollection, 5439, "tracks", "Take a Chance on Me") , tracks should have the string Take a Chance on Me as the last element." but to my knowledge the code is pristine and is exact to the supposed solution when you hit the get hint link. Frustrating beyond belief. Someone let me know where it went wrong pls??

I went line by line using the hints and forum for help. Ultimately after failing to properly complete the exercise I typed the exact code written in the first solution and it literally returned every bullet on the exercise as wrong. Did the exercise get updated and no one bothered to make a new solution or hints for it or something? I want to learn this for real, but so far having a hard time.

The code and the logic behind the code makes sense to me when I break it down and try to put it into spoken language yet the website returns that the code is completely wrong in all facets to do any of the tasks/functions asked in the example. It did not even return a single check for any of the 7 bullets in the exercise. Please help!

  **Your code so far**

// 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) {
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(recordCollection, 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/96.0.4664.110 Safari/537.36

Challenge: Record Collection

Link to the challenge:

1 Like

What’s your updated code?

ooh, this way madness lies - I always assume that there is something wrong with my code, even when it seems to be working correctly

2 Likes

That’s actually a useful attitude for sure, but the code is a straight rip from the officially linked solution and is still not working. Can you review the code and give me any tips?

I strongly recommend against copying the answer. You don’t learn anything that way.

Anywho, the solutions work just fine when I copy-paste them and run them, so it would help if you show us what your current code is. There has to be a difference.

1 Like

I began copying the answer to see if it would work, but so far it has not for me. I did not immediately resort to copying the answer on the first go if that is what you are warning about.
When I copy and paste either solution it still does not complete the checklist and will not give me exercise completion message. Currently I am using FCC on google chrome if that matters. I began to suspect it was my formatting or maybe that I was not copy-pasting right, but after tweaking still no luck.
This is the way I have the code currently written -

function updateRecords(records, id, prop, value) {
  if (prop != "tracks" && value != "") {
    records[id][prop] = value;
} else if (prop === "tracks" && records[id][prop].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;
}

and these are the unfulfilled bullets in the checklist currently(they actually increased from 1 yesterday to 3 today despite the code being the same to my knowledge) Should I just try to learn a different method to accomplish these task? I would not know where to start though since I am working almost exclusively off of previous python experience and the first 113 exercise javascript basics tutorial on FCC. It is a little bit daunting if I have to look far outside of the scope of the javascript basics tutorial to even complete it. :frowning:

After updateRecords(recordCollection, 5439, "tracks", "Take a Chance on Me") , tracks should have the string Take a Chance on Me as the last element.

After updateRecords(recordCollection, 2468, "tracks", "Free") , tracks should have the string 1999 as the first element.

After updateRecords(recordCollection, 2548, "tracks", "") , tracks should not be set

This line has an issue which causes it to catch every case, thus failing all tests the next two conditions are supposed to handle.

Hence the failing tests are about updating and deleting “tracks”.

I’ve edited your post for readability. When you enter a code block into a forum post, please precede it with a separate line of three backticks and follow it with a separate line of three backticks to make it easier to read.

You can also use the “preformatted text” tool in the editor (</>) to add backticks around text.

See this post to find the backtick on your keyboard.
Note: Backticks (`) are not single quotes (’).

Immediately or not, copying is a very bad idea.


Yea, there is a woops here.

Can you help me to understand conceptually what is happening and should I write my own version of code and refrain from ever retyping any code found in solutions going forward to better understand the concepts presented here?

That’s the entire idea for the forum. You ask questions here and we can give you hints that let you get to the answer without copying :slight_smile:

else if (prop === "tracks" && records[id].hasOwnProperty("tracks") === false) {
records[id][prop] = [value];
}

Can you help to conceptually understand this line? Is it saying if the property is “tracks” and the album does not have a “tracks” property and to add an array that will receive a value if those other 2 pre-requisites are met? Even when I type that I only kind of understand It. Are we drawing “tracks” from the update records function and then adding a “tracks” array and values to it where missing?

There are two conditions joined by the logical and &&

This one isn’t too bad. It checks if the prop is "tracks"

This one is trickier. We are looking at records[id]. Well, if we look at the recordCollection object

const recordCollection = {
2548: {
  albumTitle: 'Slippery When Wet',
  artist: 'Bon Jovi',
  tracks: ['Let It Rock', 'You Give Love a Bad Name']
}, // ...
};

records[id] will be a particular entry, such as

2548: {
  albumTitle: 'Slippery When Wet',
  artist: 'Bon Jovi',
  tracks: ['Let It Rock', 'You Give Love a Bad Name']
}

The next part is .hasOwnProperty("tracks"). That is described here: https://www.freecodecamp.org/learn/javascript-algorithms-and-data-structures/basic-javascript/testing-objects-for-properties

The === false bit is a silly way to write this, but is checking that the result from hasOwnProperty() is not true.

1 Like

Thanks so much for the help!
I got it to work by adjusting the code, but I just want to make sure I understand this at it’s foundation since after all I did use the hints to help me come to the solution.
So when written like

records[id].hasOwnProperty("tracks") === false

We are looking* at records[id] which corresponds with the different entries* in musical album collection i.e. 2468 and then with the .hasOwnProperty(“tracks”) we are checking* if those entries have a property called tracks. Is the === false just to single out the record entries that do not have a “tracks” property?

  • If there are better words to describe what’s going on instead of “looking”, “entries”, and “checking” I’d love to hear them.

Thanks again!

No, it’s just checking the return-value of .hasOwnProperty("tracks). Look at the example records in the code, it’s nested objects. The ID refers to a single entry and that entry has nested entries. If any of these entries is “tracks”, the function returns “true” and “false” otherwise.

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