Looking at the for loop. The goal is to have the interest calculated based on the latest value variable. Currently, the script generates the same interest rate and value for each year. What I desire is for it to use the previous value variable to determine the new value for each year. Here is the output in a browser: Year: 1 Interest: 750 Value: 10750
Year: 2 Interest: 750 Value: 10750
Year: 3 Interest: 750 Value: 10750
Year: 4 Interest: 750 Value: 10750
Year: 5 Interest: 750 Value: 10750
Initial investment amount = 10000 Interest rate = 7.5 Years = 5 Future Value is 10750
Thank you for using the Future Value application. Both the value and the interest should be incrementing.
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>Future Value Application</title>
<script>
var futureValue;
var investment = prompt("Enter investment amount as xxxxx.xx", 10000);
investment = parseFloat(investment);
var rate = prompt("'Enter interest rate as xx.x", 7.5);
rate = parseFloat(rate);
var years = prompt("Enter number of years", 10);
years = parseInt(years);
// calculate future value
futureValue = investment;
for (var i = 1; i <= years; i++ ) {
var cInterest;
var value;
document.write("Year: " +(i) + "<br>");
cInterest = futureValue * rate / 100;
cInterest = parseInt(cInterest);
document.write("Interest: " + cInterest + "<br>");
value = futureValue + cInterest;
value = parseInt(value);
document.write ("Value: " + value + "<br><br>");
cInterest += value;
}
futureValue = parseInt(futureValue);
</script>
</head>
<body>
<main>
<script>
document.write("Investment amount = " + investment);
document.write(" Interest rate = " + rate);
document.write(" Years = " + years);
document.write(" Future Value is " + (futureValue + futureValue* rate / 100) + "<br><br>");
</script>
Thanks for using the Future Value application.
</main>