-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcompoundInterest.js
32 lines (25 loc) · 926 Bytes
/
compoundInterest.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
function generateTable(form){
let amount;
let rate;
let years; //years for principle to grow
let interest;
let table;
let year = 1; //the year being calculated
amount = form.elements["deposit"].valueAsNumber;
rate = form.elements["rate"].valueAsNumber;
years = form.elements["years"].valueAsNumber;
table = "<table>" + "<tr><th>Year</th><th>Starting value</th>" + "<th>Interest Earned</th><th>Ending Value</th></tr>";
while(year <= years){
table += "<tr>";
table += "<td>" + year + "</td>";
table += "<td> $" + amount.toFixed(2) + "</td>"
interest = amount * rate/100;
table += "<td> $" + interest.toFixed(2) + "</td>";
amount+=interest;
table += "<td> $" +amount.toFixed(2) + "</td>";
table+="</tr>";
year++;
}
table+="</table>";
document.getElementById("result").innerHTML = table;
}