Hello All! I am able to delete tasks, however, am having trouble reducing the dollar amount of the deleted task from the total upon deleting that task. Any help would be greatly appreciated! Invoice Creator (scrimba.com)
Sorry @uconnwbball, missed this post!
So I think you’re just removing the deleted task from the DOM and not actually from the array itself. Could you have another look and see if you can find a way to remove it from the array and then render the array totals again?
Hi Roku! I see what you are saying–even after I remove the deleted task from the DOM, it is still in the totals array! I think I need to create a function that takes in the id of the task to delete as a parameter, and then removes it from the array. I was able to make all tasks objects, with a random ID and total$ properties, and I updated the reduce function so it still calculates the grand total correctly. I started a removeItem() function, but am not sure how to get it working.
Good progress! I think there is just some variable passing that might be incorrect. To make your removeItem function work properly with your setup, we need to adjust how you’re identifying the item to remove. Currently, you’re trying to find an item in the total array by its id, but you’re passing the task name (data-share) in the dataset. You’ll need to update the logic to remove the correct item from the total array using its unique id.
You can check the changes I did here: invoice-code-update - Diffchecker
Also, here is another way to do it with UUID’s as that might bloat your code (unless you wanted to try out the uuid library for this case): invoice-creator-no-uuid. This approach doesn’t use external libraries and just purely with array index. I recommend you check out this style too and see which one you prefer.