-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathindex.html
106 lines (105 loc) · 3.99 KB
/
index.html
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
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8" />
<title>App1</title>
</head>
<body>
<div>
<table style="margin: auto;">
<tr>
<td>Principal</td>
<td>
<input type="text" id="txtPrincipal" value=" " />
</td>
</tr>
<tr>
<td>Term</td>
<td>
<input type="text" id="txtTerm" value=" " />
months
</td>
</tr>
<tr>
<td>Interest Rate</td>
<td>
<input type="text" id="txtInterestRate" value="36" /></td>
</tr>
<tr>
<td>Add Interest every </td>
<td>
<input type="text" id="txtCompound" value="0" />
months
</td>
</tr>
<tr>
<td colspan="2" align="center">
<input type="submit" id="btnCalculate" value="Calculate" onclick="Calc();" />
</td>
</tr>
</table>
<div id="divResult" style="display:block;">
<table id="tblResult" style="margin : auto;">
<tr>
<td>Simple Interest</td>
<td id="tdSIInterest"></td>
</tr>
<tr>
<td>SI Amount</td>
<td id="tdSIAmount"></td>
</tr>
<tr>
<td colspan="2"></td>
</tr>
<tr>
<td>Compound Interest</td>
<td id="tdCIInterest"></td>
</tr>
<tr>
<td>CI Amount</td>
<td id="tdCIAmount"></td>
</tr>
<tr>
<td>
<span id="spnResult"></span>
</td>
</tr>
</table>
</div>
</div>
<script type="text/javascript">
function Calc() {
var principal = +document.getElementById('txtPrincipal').value;
var interest = +document.getElementById('txtInterestRate').value;
var term = +document.getElementById('txtTerm').value;
var compound = +document.getElementById('txtCompound').value;
var SI = Math.round(principal * interest * term / 1200);
var CIResult = '';
document.getElementById('tdSIInterest').innerText = SI;
document.getElementById('tdSIAmount').innerText = SI + principal;
if (compound > 0) {
var currentInterest = principal * interest / 1200;
var currentPrincipal = principal;
var currentTerm = term;
while (currentTerm > 0) {
var n = compound < currentTerm ? compound : currentTerm;
currentTerm = currentTerm - n;
var termInterest = Math.round(currentPrincipal * interest / 1200) * n;
CIResult += '\nPrincipal : ' + currentPrincipal + '\n';
CIResult += Math.round(interest * currentPrincipal / 1200) + ' * ' + n + ' month(s) : ' + termInterest + '\n';
currentPrincipal += termInterest;
CIResult += 'Total at end of ' + (term - currentTerm) + ' month(s) : ' + currentPrincipal + '\n';
}
document.getElementById('tdCIInterest').innerText = currentPrincipal - principal;
document.getElementById('tdCIAmount').innerText = currentPrincipal;
}
else {
document.getElementById('tdCIInterest').innerText = SI;
document.getElementById('tdCIAmount').innerText = SI + principal;
}
document.getElementById('divResult').style = 'display:inline;';
document.getElementById('spnResult').innerText = CIResult;
}
</script>
</body>
</html>