then, I think it is changed
but i don’t understand where this is going
why don’t you try it? paste that snippet in the editor of the challenge and see what the console says
alright in a second.
{ ‘23’: { tracks: [ ‘Happy Birthday’, ‘Jingle Bells’ ] } }
it combined them ,
so you have changed your function I imagine. Does this version pass the tests?
no . here is how my current code looks like:
function updateRecords(object, id, prop, value) {
if(prop !== "tracks" && value === ""){
object[id][prop] = value;
}else if(prop === "tracks" && !object[id].hasOwnProperty("tracks")){ object[id][prop]= [value];
}else if(prop === "tracks" && value !== ""){
object[id][prop].push(value);
}else if (value === ""){
delete object[id][prop];
}
return object;
}
let records = {
23: {
tracks: ["Happy Birthday"]
}
}
updateRecords(records, 23, "tracks", "Jingle Bells");
console.log(records);
updateRecords(collection, 5439, 'artist', 'ABBA');
and this is what the system output says:
// running tests
After updateRecords(collection, 5439, "artist", "ABBA"), artist should be ABBA
After updateRecords(collection, 2548, "artist", ""), artist should not be set
After updateRecords(collection, 1245, "albumTitle", "Riptide"), albumTitle should be Riptide
// tests completed
// console output
{ '23': { tracks: [ 'Happy Birthday', 'Jingle Bells' ] } }
{ '23': { tracks: [ 'Happy Birthday', 'Jingle Bells' ] } }
this update the value of a property to an empty string
guess what ? I found it . I mean the problem. see the first if condition. I might have accidently deleted the [id} from object[id][prop]
hence the lesson was not completed .
But I still have an question : how to read object[id][prop] ?
object[id]
is the nested object, so object[id][prop]
is the value of a property of the nested object
Thank you I’m really grateful for your help .