Any idea why this solution is wrong?

I’m trying to solve this challenge for 2 hours. I tried to not look the answer because I wanted to test myself.
My code gives all the needed works but still it won’t accept as correct. I’ve looked for every value as output and they all seem as needed. Any idea why this may not accepted?

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 !== "") {
    recordCollection[id][prop] = value;
  }

  else if ( prop === "tracks" && !(recordCollection[id].hasOwnProperty("tracks")) ) {
    let arr = [];
    arr.push(value);
    recordCollection[id].tracks = arr;
  }

  else if ( prop === "tracks" && (value !== "")) {
          recordCollection[id].tracks.push(value);
  }

  else if ( value === "") {
      if ( prop === "tracks") {
      delete recordCollection[id].tracks;
      }
      else {
      delete recordCollection[id].artist;
      }
  }

  return records;
}

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/15.1 Safari/605.1.15

Challenge: Record Collection

Link to the challenge:
https://www.freecodecamp.org/learn/javascript-algorithms-and-data-structures/basic-javascript/record-

And you can copy paste below to see all the output with correct values.

updateRecords(recordCollection, 5439, ‘artist’, ‘ABBA’);

console.log(recordCollection[5439].artist);

updateRecords(recordCollection, 5439, “tracks”, “Take a Chance on Me”)

console.log(recordCollection[5439].tracks);

updateRecords(recordCollection, 2548, “artist”, “”);

console.log(recordCollection[2548].artist);

updateRecords(recordCollection, 1245, “tracks”, “Addicted to Love”);

console.log(recordCollection[1245].tracks);

updateRecords(recordCollection, 2468, “tracks”, “Free”);

console.log(recordCollection[2468].tracks);

updateRecords(recordCollection, 2548, “tracks”, “”);

console.log(recordCollection[2548].tracks);

updateRecords(recordCollection, 1245, “albumTitle”, “Riptide”);

console.log(recordCollection[1245].albumTitle);

console.log(recordCollection);

You should never reference this global variable inside of your function.

I should have use “records” instead. Thank you.

2 Likes