Record collection - Difficulty to understand a condition

Hello,

I have difficulty to understand this:

If value is empty ( "" ), delete the given prop property from the album.

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

What I understand from this is :

  • if value is empty then I have to delete the artist property. Am I wrong? Because I did this and it doesn’t work:
if(value===""){
    delete collection[id][prop];
    return collection;
  }

This algorithm does what I want but apparently it’s not the the challenge wants.

Would you please help me without giving me the answer please.

Thanks

i am not sure how many recodrs u have but i think u must loop all records and check for empty values

I’m sorry but there is no loop to do. Here is the link to the challenge if needed : https://learn.freecodecamp.org/javascript-algorithms-and-data-structures/basic-javascript/record-collection/

1 Like

post all of your code
if it doesn’t work there is something else going on

Here is the complete code:

function updateRecords(id, prop, value) {
  if(prop!=='tracks' && value!==""){
    collection[id][prop]=value;
    return collection;
  }
  
  if(prop==='tracks' && collection[id].hasOwnProperty(prop)){
    collection[id].tracks.push(value);
    return collection;
  }
  else{
    collection[id].tracks=[];
    collection[id].tracks.push(value);
    return collection;
  }

  //This one doesn't complete the challenge
  if(value===""){
    delete collection[id][prop];
    return collection[id];
  }
}

This is the result:

 else if (value !== "") {
    collection[id][prop] = value;
  } else {
    delete collection[id][prop];
  }

I don’t want you to give me the answer. I understand that you want to help me but giving me the answer doesn’t help at all. Plus, your code doesn’t work. I just want a little hint to find it by myself.

I found the solution. I just needed to move the last if to the first place.

1 Like