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/