e.u
August 20, 2019, 9:52pm
1
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
e.u
August 20, 2019, 10:06pm
3
1 Like
ilenia
August 20, 2019, 10:07pm
4
post all of your code
if it doesn’t work there is something else going on
e.u
August 20, 2019, 10:15pm
5
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];
}
e.u
August 20, 2019, 10:25pm
7
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.
e.u
August 20, 2019, 10:37pm
8
I found the solution. I just needed to move the last if
to the first place.
1 Like