What's wrong in my code?

Q: https://www.freecodecamp.org/learn/javascript-algorithms-and-data-structures/basic-javascript/record-collection

My solution:

// 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) {
  value === "" ? delete records[id].prop : 
  (prop !== "tracks" ? records[id].prop = value :
  (records[id].hasOwnProperty("tracks") ? tracks.push(value) : () => {
    records[id].tracks = [];
    tracks.push(value);
  }));
  

  return records;
}

updateRecords(recordCollection, 5439, 'artist', 'ABBA');

Where I am doing mistake?

Hi there and welcome to our community!

I have edited your post to make your code legible on the forum.
When you wish to post code, please enclose it between two sets of triple backticks.
You can do this manually or use the Preformatted Text Tool (</> icon or CTRL+e), to create them automatically.

If “prop” is a variable try a different method of referring to it in the object

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