It looks like you haven't shared all the code for your JavaScript function. I'll give you a generic solution to calculate the cart total, and you can adapt it to your code.
Here's an example of a JavaScript function that calculates the cart total, assuming you have a list of items with their prices: