Not sure why my code is not passing

Tell us what’s happening:
Here are the test cases that the code is failing in:

After

updateRecords(recordCollection, 2548, "artist", "")

,

artist

should not be set After

updateRecords(recordCollection, 2548, "tracks", "")

,

tracks

should not be set

  **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(records[id].hasOwnProperty(prop)){
  if(prop == 'tracks' && value != ""){

    records[id][prop].push(value); 

  } else if(value != "") {
    
    records[id][prop] = value;
    
  }
} else if(prop == 'tracks'){
  records[id][prop] = []

  if (value != ""){

    records[id][prop].push(value); 
  }

}else if (value != "") {
  records[id][prop] = value;
}
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/537.36 (KHTML, like Gecko) Chrome/89.0.4389.114 Safari/537.36.

Challenge: Record Collection

Link to the challenge:

Where are you covering the case of value == ""?

If value == “”, then I do nothing with the exception to prop == “tracks” and tracks does not exist. In that one edge case, I set tracks to . In all other cases with value == “”, I do nothing.

If value is an empty string, delete the given prop property from the album.

2 Likes

@JeremyLT Wow, thank you! That worked! I do not know how I missed that in the requirements.

1 Like

Oh, it happens to us all from time to time.

1 Like

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