why do i keep getting an error message with my javascript

15 views Asked by At

I keep getting the error message:

 store.js:102  Uncaught TypeError: Cannot set properties of undefined (setting 'innerText')
    at updateCartTotal (store.js:102:70)
    at HTMLButtonElement.removeCartItem (store.js:41:5)
updateCartTotal @ store.js:102
removeCartItem @ store.js:41

it doesn't update the total cart price

The java script is as follows

function updateCartTotal() {
    var cartItemContainer = document.getElementsByClassName('cart-items')[0]
    var cartRows = cartItemContainer.getElementsByClassName('cart-row')
    var total = 0
    for (var i = 0; i < cartRows.length; i++) {
        var cartRow = cartRows[i]
        var priceElement = cartRow.getElementsByClassName('cart-price')[0]
        var quantityElement = cartRow.getElementsByClassName('cart-quantity-input')[0]
        var price = parseFloat(priceElement.innerText.replace('$', ''))
        var quantity = quantityElement.value
        total = total + (price * quantity)
    }
    total = Math.round(total * 100) / 100
    document.getElementsByClassName('cart-total-price')[0].innerText = '$' + total
0

There are 0 answers