I do not know why my code does not pass the "Record Collection" Test

Tell us what’s happening:
Describe your issue in detail here.

I think I coded all that test requires, also I did a test so I can figure out why It keeps failing and results shows me every thing the test is asking for, that is why i do not understand what is happening.

This is the Record Collection Test :

Record Collection

You are given an object literal representing a part of your musical album collection. Each album has a unique id number as its key and several other properties. Not all albums have complete information.

You start with an updateRecords function that takes an object literal, records, containing the musical album collection, an id, a prop (like artist or tracks), and a value. Complete the function using the rules below to modify the object passed to the function.

  • Your function must always return the entire record collection object.
  • If prop isn’t tracks and value isn’t an empty string, update or set that album’s prop to value.
  • If prop is tracks but the album doesn’t have a tracks property, create an empty array and add value to it.
  • If prop is tracks and value isn’t an empty string, add value to the end of the album’s existing tracks array.
  • If value is an empty string, delete the given prop property from the album.

Note: A copy of the recordCollection object is used for the tests.

I will be grateful If you can help me.

  **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 (value === "") {
  delete recordCollection[id][prop];
} else if (prop === "tracks") {
  recordCollection[id][prop] = recordCollection[id][prop] || [];
  recordCollection[id][prop].push(value);
} else {
  recordCollection[id][prop] = value;
}
return records;
}

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"]);


  **Your browser information:**

User Agent is: Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/102.0.5005.115 Safari/537.36 OPR/88.0.4412.75

Challenge: Record Collection

Link to the challenge:

Your function takes 4 parameteres:

But inside your function you are doing many things with:

That’s the problem to start with.

1 Like

Thanks, I had not noticed that little mistake.