JavaScript Simple Application: Compound Interest
JavaScript Simple Application: Compound Interest
Introduction
.
.
.
Practical Learning: Creating the Application
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8" />
<title>Compound Interest</title>
</head>
<body>
<h1>Compound Interest</h1>
<form name="CompoundInterest" method="post">
<table>
<tr>
<td><label for="principal" style="font-weight: 600;">Principal:</label></td>
<td><input type="text" id="principal"
class="principal" style="width: 80px" /></td>
</tr>
<tr>
<td><label for="interestRate" style="font-weight: 600;">Interest Rate:</label></td>
<td><input type="text" id="interestRate" class="interestRate"
style="width: 60px" />%</td>
</tr>
<tr>
<td><label for="periods" style="font-weight: 600;">Periods:</label></td>
<td><input type="text" id="periods" class="periods" style="width: 80px" />
<select class="frequency">
<option>Years</option>
<option>Months</option>
<option>Days</option>
</select></td>
</tr>
<tr>
<td> </td>
<td><input type="button" value="Calculate"
class="calculate" style="width: 80px" /></td>
</tr>
<tr>
<td><label for="interestAmount" style="font-weight: 600;">Interest Amount:</label></td>
<td><input type="text" class="interestAmount"
style="width: 80px" />
</td>
</tr>
<tr>
<td><label for="futureValue" style="font-weight: 600;">Future Value:</label></td>
<td><input type="text" class="futureValue"
style="width: 80px" />
</td>
</tr>
</table>
</form>
<script>
var princ = document.querySelector('.principal');
var iRate = document.querySelector('.interestRate');
var per = document.querySelector('.periods');
var iAmount = document.querySelector('.interestAmount');
var future = document.querySelector('.futureValue');
var frequency = document.querySelector('.frequency');
var selected = document.querySelector('select');
var btnCalc = document.querySelector('.calculate');
var para = document.querySelector('p');
btnCalc.addEventListener('click', function () {
if (selected.value == 'Years') {
interest = princ.value * iRate.value * per.value / 100.00;
}
if (selected.value == 'Months') {
interest = princ.value * (iRate.value / 100.00) * (per.value / 12);
}
if (selected.value == 'Days') {
interest = princ.value * (iRate.value / 100.00) * (per.value / 360);
}
var total = Number(princ.value) + interest;
future.value = total.toFixed(2);
iAmount.value = interest.toFixed(2);
});
</script>
</body>
</html>
| Principal: | 8650 |
| Interest Rate: | 8.725 |
| Periods: | 4 |


| Principal: | 18745 | |
| Interest Rate: | 6.825 | % |
| Periods: | 52 | Months |

|
|
|||
| Home | Copyright © 2001-2026, FunctionX | Monday 30 March 2026, 10:51 | Home |
|
|
|||