I know that others have had this error thrown but I think I have some sort of syntax problem that's causing this to happen for me. If you can find it I would be grateful. I'm new to JavaScript and have been staring at this simple program for an hour.
Here's the JavaScript:
"use strict";
var $ = function(id) {
return document.getElementById(id);
};
var calculateFV = function(investmentAmount, interestRate, yearsAmount) {
var futureValue;
//get the future value after the amount of years entered
for (var i = 1; i <= yearsAmount; i++ ) {
var interest = futureValue * interestRate / 100;
futureValue = futureValue + interest;
}
return futureValue.toFixed(2);
};
var processEntries = function(investmentAmount, interestRate, yearsAmount) {
var investment = investmentAmount;
var interest = interestRate;
var years = yearsAmount;
var futureValue = calculateFV(investment, interest, years);
$("calculate").value = futureValue;
};
window.onload = function() {
$("calculate").onclick = processEntries;
};
And here's the HTML:
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title>Future Value Calculator</title>
<link rel="stylesheet" href="future_value.css">
<script src="future_value.js"></script>
</head>
<body>
<main>
<h1>Future Value Calculator</h1>
<label for="investment">Total Investment:</label>
<input type="text" id="investment"><br>
<label for="rate">Annual Interest Rate:</label>
<input type="text" id="rate">%<br>
<label for="years">Number of Years:</label>
<input type="text" id="years"><br>
<label for="future_value">Future Value:</label>
<input type="text" id="future_value" disabled><br>
<label> </label>
<input type="button" id="calculate" value="Calculate"><br>
</main>
</body>
</html>
Thanks so much!