Record Collection

Hello.

I am having a bit of trouble with JavaScript exercise Record Collection.

Could someone just explain these directions to me in better english?

For the given id in collection:

If prop does not contain the key "tracks", then update or set the value for that incomplete prop.

If prop does not contain the key "tracks" before you update it, create an empty array before pushing a track to it.

If prop does contain the key "tracks" and its value is non-blank, then push the value onto the end of its existing tracks array.

If value is blank, delete that prop.

Thanks!!!

You’ll write a function that takes 3 arguments: id, prop, and value. The function will update your record collection, which is a single JSON object.

"2548": {
      "album": "Slippery When Wet",
      "artist": "Bon Jovi",
      tracks: [ 
        "Let It Rock", 
        "You Give Love a Bad Name" 
      ]
    }

The parameter id refers to the object name, ie 2548. The parameter prop (short for property) refers to either album, artist, or tracks. Your function needs to update the collection at the given id according to the other parameters. For example, calling the function like this…

updateRecords("2548", "tracks", "Livin` on a Prayer");

… will result in the above record looking like this

"2548": {
      "album": "Slippery When Wet",
      "artist": "Bon Jovi",
      tracks: [ 
        "Let It Rock", 
        "You Give Love a Bad Name",
        "Livin` on a Prayer"
      ]
    }

What would happen if I called the function with different parameters?

updateRecords("2548", "artist", "Bon Jovi and Richie Sambora");

@elvis016, your input is always valuable, but please don’t post solutions, especially when someone is just looking to understand the problem.

@PortableStick
Has removed and thanks for advice.

1 Like