Difficulty passing tests 5 and 6 on the Record Collection Problem

Tell us what’s happening:
I am having trouble getting my function to pass the sixth and fifth test cases, which are 1) that the song titled ‘1999’ should remain at the front of the array titled ‘tracks’ and that 2) the key ‘tracks’ should be deleted from the object representing Bon Jovi.

What’s even more confusing is that I’ve checked the actual solution to this problem, and as far as I can tell they should be returning the same result. The only difference is that I haven’t specified strict matching on data type, which I can’t really see as being an issue here.

Any ideas?

  **Your code so far**

// Setup
var 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 != "") {
  records[id][prop] = value;
} else if (prop == "tracks" && records.hasOwnProperty("tracks") == false) {
  records[id][prop] = [value];
} else if (prop == "tracks" && value != "") {
} else if (value == "") {
  delete records[id][prop];
return records;

updateRecords(recordCollection, 5439, 'artist', 'ABBA');
  **Your browser information:**

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

Challenge: Record Collection

Link to the challenge:

Is it the records array that has the property?

Hi Jeremy. I was going to say yes, but now that I think about it, records is an object with keys that serve as the album IDs that relate to values that are themselves objects. So I’m thinking the second argument in the first ‘elif’ statement should be ‘records[id].hasOwnProperty(“tracks”)’ instead of what I have currently.

At least, I think that’s what you’re trying to point out. Either way, thanks for pitching in!

1 Like

Yep, you want to know if the specific record (id) has any tracks.

1 Like

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