Super confused at the record collection task

I can program pretty complex things in Java already and I’m just learning JS and other things because I need it for projects. Even though JS should be the same in terms of applying algorithms, this lesson just kind of stumped me.

I don’t know if I failed to understand something or if it’s the big amount of rules, but I just found it quite hard to get the solution because I did not really know where to start with checking all the conditions. I also don’t really understand what the exercise wanted me to do exactly because it says add a value if it’s not tracks and the value isn’t null, so that makes sense. However the part where you have to check if tracks exists and then make tracks and then add something to tracks if it’s not null…? I really don’t get the order I should write those if statements in.

Can someone explain to me what the thought process here is or where the solution comes from? I just don’t really get it.

The other properties you can just set to whatever the value is. What is different about the tracks property?

Note that you can write the logic in exactly the order that it is described, you can almost take the description word-for-word and just turn it into the equivalent code. If you change the order, you can remove some of the checks for each property, but that’s about the only optimisation that’s possible here; the challenge really only asks you to understand what JS syntax matches what description of each step.

1 Like

Never mind I figured it out 20 minutes after posting this.
Basically I approached it wrong. I was following the instructions exactly which kind of confused me, while it was better to first check if it was specifically tracks and then put it in there if it exists and if it doesn’t make an array and put it in there.
And then do the rest of the checks.

It’s just the I could not keep the oversight on the whole thing from the amount of things it wanted you to do, but it’s worth doing in the end because I feel like I learned a thing or two.

What throws me off with JS is honestly the lack of type declarations and the freedom in adding and removing things from objects as dumb as it sounds, I find languages with types more easy to work with but maybe it’s only because I’m not used to not declaring any types.