Example output
To create an investment calculator that allows for annual additions and interest payments, you can follow these steps:
function calculate() {
// Get form field values
var initialAmount = parseFloat(document.getElementById("initial-amount").value);
var annualAdditions = parseFloat(document.getElementById("annual-additions").value);
var interestRate = parseFloat(document.getElementById("interest-rate").value);
var frequency = parseInt(document.getElementById("frequency").value);
// Calculate investment value
var years = 10; // Change this to the number of years the investment will be held
var investmentValue = (initialAmount + (annualAdditions * years)) * Math.pow((1 + (interestRate / frequency)), (years * frequency));
// Display result
document.getElementById("investment-value").value = "$" + investmentValue.toFixed(2);
}
To use this code, you can copy and paste the HTML,