Basic JavaScript - Record Collection

Tell us what’s happening:
Not understanding why [id] is included in the updateRecords function. Removing these tags marks the code as incorrect - so it must hold value lol.

I understand basically every other grain of code here, but cannot logically reason as to why the [id] tag is neccessary.

Any help is appreciated. Thank you!

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

Your browser information:

User Agent is: Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/ Safari/537.36

Challenge: Basic JavaScript - Record Collection

Link to the challenge:

Each album has a unique id number as its key and several other properties.

If you look at the sample object literal, do you see these id numbers?

Yes; however I guess what Im not fully understanding is this; is that [id] tag just included so that the function recognizes which track/album I am referring to?

sorry, I forgot to make it a reply, and just commented by mistake

Yes. The id identifies a specific album object in the full record collection object

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