I don't even know where or how to begin

Tell us what’s happening:
Describe your issue in detail here.

This challenge is overwhelming to me and I don’t just want to copy the solution. I just can’t conceptualize how to begin tackling this problem. Any help would be appreciated. I just need a hand to hold I guess.

I really can’t wrap my head around the functions parameters and what to do with them. They just seem like arbitrary names to me right now.

  **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;
}

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

Challenge: Record Collection

Link to the challenge:

Think of it in parts, ‘divide and conquer’ is a very common strategy in what you’re trying to learn. The test cases are a good starting point here.

Let me try with that one!
records - the whole collection one of which you will likely update
id - the identifier of a singular record - take a look at the objects in the recordCollection sample, they seem to be arbitrally labelled with numbers - like 2548 for Slippery When Wet for example
prop - any of the names of properties of a singular record object. The provided ones have the following possible props: “albumTitle”, “artist”, “tracks”
value: it’s just that , a value - it can be anything that you will set a given prop / object key to

Let’s break it down:

  • Your function must always return the entire record collection object.

my suggestion is to think of ways you can do that, do you know any functions that can go over an array / iterate over keys of an object and return a value ? Perhaps you know how to find if an object has a given key? If you use id you can tell if the record you want to update exists or it’s enough to just insert a new one :slight_smile:

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

hint: prop is just a key on the object you are working with. The instructions give example of artist or tracks, but at this stage I would assume it can be anything in the object. It simply means you have to set the key (prop) of the object you are working against (one of the records) to the value.
a simple

obj[prop] = value

should suffice.

  • 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.

here is where you have to decide if you want to use conditionals or perhaps a switch statement. The action logic diverges, you either do a or b. Either set a prop blindly to the new value or add to the existing one.

  • If value is an empty string, delete the given prop property from the album.

Here is another condition.

2 Likes

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