Here is the problem:
Write a program to find future value of monthly investments. Start with an initial investment, make a deposit every 30days, calculate interest on principle compounded daily, display a table showing beginning balance, deposit for the year, interest
earned for the year, and ending balance. The table should display the aforementioned
information for a duration of your present age to 65. Display result in a table format as shown below.
Here is the code so far.....
<html>
<head>
<title>Future Value Calculation</title>
<style type = "text/css">
table { width: 100% }
th { text-align : left }
th span { color: #008; margin-left: 15px; }
</style>
<script type = "text/javascript">
window.onload = function()
{
var EndBal;
var principal = 2000.00;
var rate = 0.12;
var deposit = 1200;
var interest;
var BegBal = principal + deposit;
for ( var age = 16; age >= 1; --age )
{
// Do calculations
EndBal = ((principal + deposit) * Math.pow(1 + rate, age ));
interest = ((principal + deposit) * Math.pow(1 + rate, age ))-(principal+deposit);
// Insert row
var row = getById("tBody").insertRow(0); //Insert row at index 0
// Create cells for the created row
// Empty cells are set to to be displayed in the table
row.insertCell(0).innerHTML = age+50;
row.insertCell(1).innerHTML = EndBal.toFixed(2);
row.insertCell(2).innerHTML = interest.toFixed(2);
row.insertCell(3).innerHTML = deposit;
row.insertCell(4).innerHTML = BegBal.toFixed(2);
BegBal = EndBal;
}
// Set the header values
getById("spnInitial").innerHTML = principal.toFixed(2);
getById("spnRate").innerHTML = rate.toFixed(2);
getById("spnDeposit").innerHTML = deposit;
getById("spnInvestment").innerHTML = EndBal.toFixed(2);
}
// Helper function to get element by id
function getById(id)
{
return document.getElementById(id);
}
</script>
</head>
<body>
<table border="1">
<thead>
<tr><th colspan="5">Future Value Calculation</th></tr>
<tr><th colspan="5">Initial Investment:<span id="spnInitial"></span></th></tr>
<tr><th colspan="5">Interest Rate:<span id="spnRate"></span></th></tr>
<tr><th colspan="5">Deposit every 30 days:<span id="spnDeposit"></span></th></tr>
<tr><th colspan="5">Investment started:<span id="spnInvestment"></span></th></tr>
<tr>
<th>Age</th>
<th>Beg Bal</th>
<th>Interest</th>
<th>Deposits</th>
<th>Ending Bal</th>
</tr>
</thead>
<tbody id="tBody">
</tbody>
</table>
</body>
</html>
But it does not calculate correctly. I need someone to help out with the loop...