Record Collection (HELP)

Tell us what’s happening:
I´ve been learning JS for some few day, and I got stuck in this exercise.
When I hit the “Run the Tests” button, It shows that it acomplishes almost every test, but fails only in two.

–> After updateRecords(1245, "tracks", "Addicted to Love") , tracks should have "Addicted to Love" as the last element.
–> After updateRecords(2548, "tracks", "") , tracks should not be set.
Your code so far

Only change code below this line

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

// Alter values below to test your code
updateRecords(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/73.0.3683.103 Safari/537.36.

Link to the challenge:
https://learn.freecodecamp.org/javascript-algorithms-and-data-structures/basic-javascript/record-collection/

I’ve changed some formats of your post for legibility. Make sure to review your post next time.

Looks like you are only failing one of the tests. updateRecords(2548, "tracks", "") ,
However, running this function still returns items in the array as it is. You need to check if you for tracks and see if it’s empty then set it either empty array.

1 Like

Yeah, I¨ll check it the next time.
By the way, thanks for the help.