Build a Record Collection - Build a Record Collection

Tell us what’s happening:

I have done all the steps except one. I am unable to find where I am wrong ?

Your code so far

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

function updateRecords(records, id, prop, value)  {
  if(value == "") {
    delete records[id][prop];
  } else if(prop != "tracks" && value != "") {
      records[id][prop] = value;
  } else if(prop == "tracks" && value != "" && records[id].hasOwnProperty("tracks") != undefined) {
      records[id][prop] = [value];
  } else if(prop == "tracks" && value != "") {
     records[id][prop].push(value);
  } return records;
}

console.log(updateRecords(recordCollection, 5439, "artist", "ABBA"))

Your browser information:

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

Challenge Information:

Build a Record Collection - Build a Record Collection

This is the 5th user story

  1. If prop is tracks and value isn’t an empty string, add value to the end of the album’s existing tracks array.

Collection initially:

{ '1245': { artist: 'Robert Palmer', tracks: [] },
  '2468': 
   { albumTitle: '1999',
     artist: 'Prince',
     tracks: [ '1999', 'Little Red Corvette' ] },
  '2548': 
   { albumTitle: 'Slippery When Wet',
     artist: 'Bon Jovi',
     tracks: [ 'Let It Rock', 'You Give Love a Bad Name' ] },
  '5439': { albumTitle: 'ABBA Gold' } }

Collection after updateRecords(recordCollection, 2468, "tracks", "Free"), with code above:

{ '1245': { artist: 'Robert Palmer', tracks: [] },
  '2468': { albumTitle: '1999', artist: 'Prince', tracks: [ 'Free' ] },
  '2548': 
   { albumTitle: 'Slippery When Wet',
     artist: 'Bon Jovi',
     tracks: [ 'Let It Rock', 'You Give Love a Bad Name' ] },
  '5439': { albumTitle: 'ABBA Gold' } }