Basic JavaScript: Record Collection - Help

Hello I’m currently on freeCodeCamp’s Javascript tutorial, and I cannot find out what’s wrong with my code. I tried reading the hint after formulating a code for it. up to no avail. Help on the matter is appreciated!

This is the link for the exercise.

function updateRecords(id, prop, value) {
  
  if (prop != 'tracks' && value != ''){
      // If prop isn't "tracks" and value isn't empty ("")
      
      collection[id][prop] = value;
      //  update or set the value for that record album's property.
      
  } else if (prop == 'tracks' && collection[id][prop] == undefined) {
      // If prop is "tracks" but the album doesn't have a "tracks" property
      
      collection[id][prop] = '[]';     
      // create an empty array  
      collection[id][prop].push(value);
      // before adding the new value to the album's corresponding property.
 
  } else if (prop == 'tracks' && value != '') {
      // If prop is "tracks" and value isn't empty ("")
   
      collection[id][prop].push(value);   
     // push the value onto the end of the album's existing tracks array.
      
  } else if (prop == 'tracks' && value == ''){
      // If value is empty ("")
      
      delete collection[id][prop];
      //  delete the given prop property from the album.
  }


  return collection;
}

This is only deleting the prop property if the prop argument is “tracks”.

1 Like

This does not work because '[]' is a string, not an array.

1 Like

Thank you for replying to this! I forgot that strings have quotes, and double-quotes surrounding them! after removing the quotes. The else-if block is now working.

Yes, it needed to the delete the property, if the propery value is empty.

Here’s and update on the code I placed on it:

else if (value == ''){
      // If value is empty ("")
      
      delete collection[id][prop];
      //  delete the given prop property from the album.
  }

You should be passing the tests now, I believe.

1 Like

Yeah! I did! thanks nhcarrigan!

1 Like

I’m glad I could help! Make sure you take some time to celebrate your success!

1 Like