I’m trying to figure out why this block of code isn’t behaving the way I’d expect. This is for a simple online financing calculator with trade in. Everything worked until I added the ‘accessories’ section to the code. Instead of returning product + accessories (e.g. $100 + $50 = $150) it’s concatenating the results (e.g. $100 + $50 = $10050). The trade in and month calculation seem to work correctly if I don’t enter any value into the accessories field.
function Calculate() {
var months = document.querySelector("#months").value;
var product = document.querySelector("#product").value;
var accessories = document.querySelector("#accessories").value;
var trade = document.querySelector("#trade").value;
var basket = product + accessories;
var total = ((basket - trade) / months).toFixed(2);
document.querySelector("#total")
.innerHTML = "Estimated Monthly Payment: $" + total;
}