Basic JavaScript - Record Collection

Tell us what’s happening:
I know this is fairly easy to accomplish without the need to do a google search or ask for help on the forum,however im actually really stuck with Objects in general as they can be for my experience kind of confusing. I am trying to return the full object and i am certain that after the object constructor you have to do an if/else statement,however i do not know if i have to return the entire object or just the desired parameters

function updateRecords(records, id, prop, value) {
records = {
id:{
prop,
value

}

}
return records;
}

// 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) {
  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/112.0.0.0 Safari/537.36 OPR/98.0.0.0

Challenge: Basic JavaScript - Record Collection

Link to the challenge:

Can you explain how this code is supposed to work? I’m not sure it meets the list of requirements.

The code should return the recordsCollection desired object.When the function is called with the properties that i want to call as parameters.

But how does it meet the entire list of requirements?

There are a bunch of conditions to check to see how to change the records object

i think you can start by:

  1. understand the whole data type in the recordCollection. e.g. Object as Properties / Array as values

  2. add this before “return records;” for debugging

console.log(records)

  1. then follows along the 4 requirements.

  2. try replace the string at bottom using the test case for debugging as well.

keywords i use are

  • delete Object[key][key]
  • Object[key][key]=value
  • Object.hasOwnProperty(key)
  • Array.push()
  • Object[key].key=value

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