The solution works, but I’m still getting errors

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

  **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) {
//delete records
if (value == "") {
  console.log(prop + " is blank. The " + prop +" property is being deleting!");
  delete recordCollection[id][prop];
  return records;
} else if 
// not tracks
  (prop != "tracks") { 
  console.log(value + " is being added as " + prop +" for entry " + id +"!");
  recordCollection[id][prop] = value;
  return records;
} else if 
// tracks but no tracks yet
  (prop == "tracks" && recordCollection[id].hasOwnProperty("tracks") == false) {
  console.log("The tracks property is being added!");
  recordCollection[id][prop] = "tracks";
  recordCollection[id][prop] = [];
  console.log("The track is being added!");
  recordCollection[id][prop].push(value)
  return records;
} else if 
// tracks but no tracks yet
  (prop == "tracks" && recordCollection[id].hasOwnProperty("tracks") == true) {
  console.log("The track is being added!");
  recordCollection[id][prop].push(value)
  return records;
}
return records;
}

updateRecords(recordCollection, 5439, 'artist', 'ABBA');
updateRecords(recordCollection, 5439, 'tracks', 'Take A Chance On Me');
updateRecords(recordCollection, 2548, "artist", "");
updateRecords(recordCollection, 1245, "tracks", "Addicted to Love");
updateRecords(recordCollection, 2468, "tracks", "Free");
updateRecords(recordCollection, 2548, "tracks", "");
updateRecords(recordCollection, 1245, "albumTitle", "Riptide");
//updateRecords(recordCollection, 5439, 'tracks', 'Dancing Queen');
//console.log(recordCollection);

//updateRecords(recordCollection, 5439, 'albumTitle', '');
console.log(recordCollection);

  **Your browser information:**

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

Challenge: Record Collection

Link to the challenge:

Hello there.

Do you have a question?

If so, please edit your post to include it in the Tell us what’s happening section.

Learning to describe problems is an important part of learning how to code.

Also, the more information you give us, the more likely we are to be able to help.


You should not hard code this global variable.

1 Like

Notice how the parameter in the function is NOT the same as the object you are deleting?
The tests are failing because as you may notice, the “test cases” are not part of the code. Soooo they are not using the “recordCollection” present in the code, hence the issue.

Oh, Ok. Thank you very much!

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