Please can someone help me understand this problem better

Tell us what’s happening:
Please be patient with me I am so new to this and I am really trying my best before posting a question. I have read other people’s explanations and they didn’t help specifically with my confusion. There is also no video for this one.
I am so confused by this question. I have spent hours re-reading it and trying to break it down. I feel extremely discouraged.
I almost feel like after just learning some of the js basics, I need more clarity in the question to help me identify what steps I need to do.
I cannot find a specific goal or question layed out in the problem. :frowning: Forgive me if I sound a bit frustrated, I am just upset that I feel I am trying to break it down and it isn’t making
sense based on the wording.
I have broken it down and examined the reasons for my confusion and I am going to present all of my questions below:

  1. “If prop isn’t tracks and value isn’t an empty string, update or set that album’s prop to value.”
    how can we identify the property using ‘prop’ in an if statement if prop is not defined to know it represents a property?
    Same question goes for “value.” If I try to think on how to define it I feel like I am wrong but I was thinking of using recordCollection.getOwnPropertyNames() somehow, but then I would have
    to include all of the objects and then an if statement based on the object’s contents.

recordCollection.getOwnPropertyNames(2548, 2468, 1245, 5439) ← no one taught about making a comma separated list like this so I believe me to be completely off base.

  1. I am interpreting value as the actual items in the key, ex: [‘Let It Rock’, ‘You Give Love a Bad Name’] and ‘Robert Palmer’, etc. So if these are the values, how does request make sense?
    “If prop isn’t tracks and value isn’t an empty string, update or set that album’s prop to value.”
    We are setting a property to the value? I don’t understand why we would do that and therefore I feel like I am understanding wrong.
    This specific confusion also makes it hard to even start my function.

  2. “If prop is tracks but the album doesn’t have a tracks property, create an empty array and add value to it.” Again the ‘value’ is tripping me up, because how can I “add value” to it?
    Does it just want me to input something random? If so, why does it say create an empty array??

  3. “If prop is tracks and value isn’t an empty string, add value to the end of the album’s existing tracks array.” Same type of confusion around value.

  4. “If value is an empty string, delete the given prop property from the album.” --This I think I understand to just represent tracks in this object. I am struggling to think of how to describe
    it as empty, but I think I am just not using my head as much because I have exhausted my brain cells on the previous issues.
    1245: {
    artist: ‘Robert Palmer’,
    tracks:
    },

    Your code so far


// Setup
var 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;
}

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/91.0.4472.164 Safari/537.36

Challenge: Record Collection

Link to the challenge:

a variable never knows anything other then the value that it holds. In this case it is a string. The programmer knows that that string is a propery name and write the code accordingly

it asks you to create a function that behaves in the way described by the bullet points

in the same way as prop, it is just a string - the programmer knows what it raprents and writes the code accordingly

I don’t think getOwnPropertyNames exist

we want a function that can update the object based on the values of id (to identify which album), prop (to identify which property) and value (to know how to update)
the details on what exactly it should do it’s in the challenge description

the tracks property is an array, to update it you add the value to the end of the array. If the tracks property doesn’t exist also the array doesn’t exist, you can’t manipulate an array that doesn’t exist so you first need to create an empty array

So in every record object, all properties except the tracks property is a straight assignment - if you are given a value, that value will be assigned to the property. What property? The one with a name matching the prop string.

So tracks is what is known as an “edge case”. It’s the curve ball. Every other time, you have a record that can be found using id, and on that record you either create a property or delete a property. If it already exists, you don’t really care - by creating it, you’re replacing it.

And that’s every case, except tracks. In the case of that one, the delete pattern is the same, but how you add is different. This is usually where the confusion arises, and the way to address it, for me, is find the edge cases and handle them, then the general rule becomes more clear.

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