Build a Record Collection - Build a Record Collection

Tell us what’s happening:

Hello. I pass all tests except for 3, it is failing because its giving the property “tracks” a duplicate value.

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

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

// console.log(updateRecords(recordCollection, 5439, "artist", "ABBA"));
// console.log(updateRecords(recordCollection, 5439, "tracks", "Take a Chance on Me"));






Your browser information:

User Agent is: Mozilla/5.0 (X11; Linux x86_64; rv:151.0) Gecko/20100101 Firefox/151.0

Challenge Information:

Build a Record Collection - Build a Record Collection

GitHub Link: freeCodeCamp/curriculum/challenges/english/blocks/lab-record-collection/56533eb9ac21ba0edf2244cf.md at main · freeCodeCamp/freeCodeCamp · GitHub

hello!

these are two if conditions and not else if, so the code will try to execute both the statements if the conditions are true.

after executing the first if , the 5439 id of recordCollection has a tracks property, which makes the second if condition true, and therefore it is also executed, pushing a copy of value in tracks.

you also need to consider here, if prop is not tracks, do you need an array?

Thanks a lot, that fixed it.