Record collection I do not understand it https://www.freecodecamp.org/learn/javascript-algorithms-and-data-structures/basic-javascript/record-collection

Hello folks I am stuck doing this exercise record collection I watched the video several times and I read about it and I can’t understand and solve it and I do not want to copy the answer cause I want to understand it so please try explain it to me

what have you tried? what is giving you issues?

1 Like

Hi @Hamza-Noah !

Welcome to the forum!

The trick to solving this is to break down each requirement.

Focus on the first condition.

  • If prop isn’t tracks and value isn’t an empty string, update or set that album’s prop to value .

What have you tried for this first condition?
Can you show us your attempt for this first part?

@Hamza-Noah we have the same dilemma. I find it really hard because the lessons are easily presented but the tasks required are very difficult. Just like you, i do not like to copy-paste other people’s solutions because i like to answer it based on my understanding of the issue. It feels like i’m missing out on something.

1 Like

I felt the same way when I went through the javascript section almost a year ago.

But I realize now that these lessons where challenging users to learn how to problem solve so you can be prepared to solve tougher challenges later on in the curriculum .

The tricky part about record collection in particular is breaking down each condition into bite size pieces.

For example:

For this first part, we can start with an if statement.

if(condition){
// update album's prop to value
}

Then you can translate this first part into code.

Another way to think of this is
if prop does not equal tracks.

The not equals sign in javascript is this !==

The first part of the if statement would be this.

if(prop !== tracks

Then you tackle the rest of the if statement

You slowly tackle bits and pieces of the conditions.
Then you can ask for help on specific sections like

What do they mean by

That way the forum can help guide you and @Hamza-Noah in a more specific manner.

But if you try to tackle everything all at once then it will be super confusing and seem impossible.

Hope that helps! :grinning:

1 Like

all of them

do you have issues understanding the requirements? finding the right code syntax? or what?
what have you tried?

first of all I understand what function, if condition, object and nested object means
this challenge is really big so I will break it down
what I understand now
it wants to update the the values of the properties is that’s right

kind of I do not completely understand the requirements

thank you for your advice it is my first post on this community

@jwilkins.oboe
so for me, I am trying to understand the code line by line what records means here in the function parameter
// Only change code below this line

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

if(value === “”){}

return records;

}

records is the parameter that will hold the object you need to update

1 Like

Ok, why do I need to hold the records as a parameter?
I am trying to understand the requirements of this challenge what I understand now it wants to update the prop’s value is that right?

Records is one of four function parameters.

(records, id, prop, value)

Records represents an object of album data.

In this function call

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

recordCollection is that object literal we are using for the tests.

Our task is to modify that record collection object by writing a series of if/else statements based on these rules here.

If prop isn't tracks and value isn't an empty string, update or set that album's prop to value.
If prop is tracks but the album doesn't have a tracks property, create an empty array and add value to it.
If prop is tracks and value isn't an empty string, add value to the end of the album's existing tracks array.
If value is an empty string, delete the given prop property from the album.

Hope that makes sense!

1 Like

Yes, for the first rule you are updating the album’s prop to value .

1 Like

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