My project is to create a website that sells pens, pencils and erasers. I need help calculating the tax and adding deals and shipping cost. If the live in Saskatchewan there is no shipping cost, the tax is 5% and if they spend at least $30 they get $5 off after taxes. If they live in Alberta there is a $2 shipping cost, the tax is 5% and there is no deals. If they live in Manitoba there is a $2 shipping cost, the tax is 6% and there is no deals.
I have tried if statements but nothing was showing up. How can I debug this?
function updateCartTotal() {
var cartItemContainer = document.getElementsByClassName('cart-items')[0]
var cartRows = cartItemContainer.getElementsByClassName('cart-row')
var order_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
order_total = order_total + (price * quantity)
}
order_total = Math.round(order_total * 100) / 100
document.getElementsByClassName('cart-total-price')[0].innerText = '$' + order_total
}
<select id="province">
<option value="saskatchewan">Saskatchewan</option>
<option value="alberta">Alberta</option>
<option value="manitoba">Manitoba</option>
</select>
I expect it to show everything put together