"Record collection" lesson (JS Algorithms and Data structures)

I managed to complete the lesson by understanding the logic behind the hints and a quick peek to the results given, which brings some confusion… I understand the concept of the exercise, however, I can’t understand something:

When creating actions like “delete records[id][prop]” or “records[id][prop].push(value)”, how does the function know that [id] and [prop] are referring to the Element (ID) inside the object and then the Property (Prop) is whatever property we assign to that parameter.

I know that we are assigning the parameters inside the function’s parenthesis but I don’t see the relation of when “id” became the element/property. Again, I know we assign the parameter but I’m not sure how the function knows that we are referring to that.

I’m not sure if I’m explaining myself properly but it’s as good as I can let it out.

A million thanks in advance.

  **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 !== "") {
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/99.0.4844.84 Safari/537.36 OPR/85.0.4341.60

Challenge: Record Collection

Link to the challenge:

the variables id, prop and value are the function parameters (together with records)

their value is determined when the function is called
for example, here:

the function is called with id having a value of 5439, prop having a value of 'artist and value having a value of 'ABBA'

they are just string, and numbers

the bracket notation for accessing objects takes a string or number, and it tries to access the property in the object with that name. There is no special connection between the number 5439 and the object. It works because the object is built that way, and by definition the function is called with an argument id that equals one of the object properties.

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