Basic JavaScript - Record Collection completely stuck

Tell us what’s happening:
Describe your issue in detail here.
First of all I have comprehension issues so if I missed anything super obvious from earlier lessons sorry. Also english isn’t my first language.

So, I’ve been stuck on this bad boy for an hour or so. I know what I need to do I think but I’m unsure of how I’m to do it. my code isn’t by any means close to done either, but I had questions that I couldn’t find the answers to so I decided it might be better to ask so I’m not tempted to cheat.

My main issue is that I don’t see where the object I’m supposed to edit is. I can’t just go value = prop but prop and value are only ever defined (I think but I might be chaotically wrong) in the updateRecords function. So how am I supposed to assign any of them to one another? Hint 2 said that to access the value in the object I need to use record[id][prop] but where is that? And What’s the difference between that and simply hasOwnProperty? And I need to create an array as well?

I’m sorry I’m embarassed to write all this out but I’ve gone back through the lessons but I just can’t see what this all is.

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) {
  return records;
} if (value == "") {
  delete 
} else if (prop != tracks && value != "") {
  value
}

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

Your browser information:

User Agent is: Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:109.0) Gecko/20100101 Firefox/118.0

Challenge: Basic JavaScript - Record Collection

Link to the challenge:

Hi there and welcome to our community!

This can be tricky to get your head around and we get a lot of requests for help with this challenge.

I’ll try to help with an understanding of the fundamentals:

The object recordCollection is an example object which can be used to test your function. However your function should be able to handle any similarly structured object. This is where the function parameters come in:

  1. records is the object which is passed to the function
  2. id is used to access individual albums within the object
  3. prop is a specified property of an individual album
  4. value is the value for the specified prop

So, if you call the function like this:

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

…your code should use the function parameters to access the ‘5439’ object within the object ‘recordCollection’ and update (or add) the ‘artist’ property as ‘ABBA’, as these are the values which are passed as the parameters recordCollection, id, prop and value respectively.

Now, to use the function parameters to access and modify the object, you can use dot or bracket notation (see below for a guide on this).

If you wanted to change the artist of the album ‘1999’ for instance, you could call the function as:

updateRecords(recordCollection, 2468, 'artist', 'the artist formerly known as Prince');

Inside your function you could modify it like this:

records[id][prop] = value

To solve this challenge, a simple approach would be to work through the rules specified in the challenge description one-by-one, writing the appropriate logic for each one. For instance, they can be written as a series of if...else statements.

I hope that’s a useful starting point at least!

I sort of understand you, but I fail to understand “records[id][prop] = value”
I assume it’s accessing the object records then the object id inside that and finally the prop inside that? But how would I know to use the object “records”? I don’t see it anywhere? Would that only be understandable once the entire function is complete?

And does the recordCollection object only serve as an example then? I thought I had to somehow directly interact with it (though you do interact with it but more indirectly).

But to summarise my understanding I use some if and if else statements to validate the conditions and then just add properties to an object (that looks like an array, why does it do that by the way, recordsCollection that is), but I do it through the updateRecords function instead of manually?

I really appreciate the help, I feel like the course really got heavy at the end here and I wasn’t prepared for it.

What is this line telling you? This first part is commonly misunderstood by beginners.

Yes I get that it’s a function but that makes it more confusing because what does records[id][prop] mean in that case?

When you call the function as (for example):

updateRecords(recordCollection, 2468, 'artist', 'the artist formerly known as Prince');

…you are passing values to the function parameters as follows:

recordCollection => records
2468 => id
‘artist’ => prop
‘the artist formerly known as Prince’ => value

Inside the function, whenever you use the parameters records, id, prop or value, you will be interacting with whatever object and values are passed to the function when it is called.

So, in this case, if you have the code records[id][prop] = value inside your function, it would update the value of the artist property from ‘Prince’ to ‘the artist formerly known as Prince’ for the album 2468 in the object recordCollection.

Of course, you need to write conditional logic as specified in the challenge description, but if you write it in terms of the function parameters, it should work for any values which are passed to those parameters when the function is called.

2 Likes

Say more. That line is not saying just “it’s a function”.

What is that stuff in the parenthesis?

1 Like

…properties of/in the function…? :face_with_spiral_eyes:

1 Like

I’m slowly starting to get it, I’ll let it sit for a bit mentally so I don’t burn myself out. I really really appreciate it though. It’s a lot to keep up with as a javababy. But you certianly leveled me so thanks!!

This stuff is hard, for sure!

Thank you, seriously. I feel like I’m halfway there almost. Afraid I’ll overextend though, but I am glad for the support!

You know, it’s not only tricky to get your head around. Sometimes, it’s tricky to explain it in a way which is simple to understand too!
Just don’t ask me any questions about recursion :rofl:

2 Likes

JavaScript is very tricky, sometimes whenever I’m confused, I kind of enlist the help of assistant AI and it’s really helpful…

1 Like

I’d certainly like to but I need all the learning I can get, afraid I’d use way too much :stuck_out_tongue:

1 Like

Hello! It’s me again, I peeked a bit at the answer because I really felt that I didn’t understand the whole picture. Anyway I was very close in my own solution. But what I still don’t understand is how you could tell that records is an object? I only ever see records inside the updateRecords function. And how would I be able to tell that [id] and [prop] are tied to records? thanks again

records is an object because you call the function with an object.

The function:

function updateRecords(records, id, prop, value) {
  // function code here
}

Calling the function assigns these values to the parameters defined above:

updateRecords(recordCollection, 2468, 'artist', 'the artist formerly known as Prince');

You could of course call the function with a different object (which would still work if the object had the same structure as recordCollection). If you passed something else (other than an object) as the first parameter, your code would simply fail or spit out nonsense.

Oh so it’s basically just assigning the name records to the actual object recordCollection?

Its assigning whatever is the first argument to ‘records’.

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