Unable to pass this one test!

I think my code is doing okay but there is this tests that is giving an error and I tried to debug but I can’t help it anymore. Any help would be appreciated!

My code so far


// Setup
var collection = {
2548: {
  album: "Slippery When Wet",
  artist: "Bon Jovi",
  tracks: [
    "Let It Rock",
    "You Give Love a Bad Name"
  ]
},
2468: {
  album: "1999",
  artist: "Prince",
  tracks: [
    "1999",
    "Little Red Corvette"
  ]
},
1245: {
  artist: "Robert Palmer",
  tracks: [ ]
},
5439: {
  album: "ABBA Gold"
}
};

// Only change code below this line
function updateRecords(id, prop, value) {
 if (prop != "tracks" && value != "") {
  // console.log("inside first conditional")
  collection[id][prop] = value;
}

if (prop === "tracks") {
  // console.log("inside second conditional")
  if (collection[id].tracks == undefined) {
    collection[id].tracks = []
  }
  if (value != "") {
    collection[id].tracks.push(value)
  } else {
    delete collection[id][prop];
  }

} 


return collection;
}

updateRecords(5439, "artist", "ABBA");

// running tests After

updateRecords(2548, "artist", "") , artist should not be set 

// tests completed

Challenge: Record Collection

Link to the challenge:

As per the instructions for this exercise it says: “If value is empty ( "" ), delete the given prop property from the album.”

So I would try adding something like if(value === "") delete collection[id][prop]; as the first line in your function, else you can continue with the rest of the logic (which looks right).

1 Like