Can not understand why the test is not passing, please help!

Tell us what’s happening:
Hello,
This is my first time posting so sorry if I’m doing something wrong.

  **My code**

// 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) {

  switch (prop){
          case 'tracks':
    if(value==""){
      return delete records[id].tracks;
    }
    // Failing test: After updateRecords(recordCollection, 5439, "tracks", "Take a Chance on Me"), tracks should have the string Take a Chance on Me as the last element.
    else{
      if(records[id].hasOwnProperty(prop) === false){ 
        console.log(records[id]);
        records[id]['tracks'] = value;
        console.log(records[id]);
       //  console.log(records[id]); --> output is { albumTitle: 'ABBA Gold', tracks: 'Take a Chance on Me' }
      }
      else{
      records[id][prop].push(value);
      return records;}}
    break;

          case 'artist':
    if(value==""){
      return delete records[id].artist;
    }
    else{
      records[id].artist = value;
      return records;}
    break;

    case 'albumTitle':
      if(value==""){
        return delete records[id].albumTitle;
      }
      else{
        records[id].albumTitle = value;
        return records;
      }
      break;

  }
}

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/99.0.4844.74 Safari/537.36

Challenge: Record Collection

Link to the challenge:

You shouldn’t hard code against every possible property value. This isn’t a good place to use a switch.

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