In: Computer Science
Do for javascript.
Create a form with the following inputs.
L -> Loan Amount in $'s, i -> Interest Rate %/year, n -> Number of Compounding Periods months
Given the following formula to solve for the monthly payments
mp = ( i * (1+i)^n * L ) / ( (1+i)^n - 1 )
Output the results
L = $, i = %/month , n = months
mp = $
And a table which lists the remaining loan amount and interest paid per/month
Month Loan Remaining Interest Paid
note : code is in JS and html
given integers in formula and given data/labels are not match................so formula will not work with given data(it also doesn't have % input).
given code will help you..........
<html>
<head>
<title>compound interest calculation</title>
<script>
function calculate()
{
p = document.getElementById("p").value;
n = document.getElementById("n").value; // no. of compound per year
t = document.getElementById("t").value; //no. of years
r = document.getElementBuId("r").value;
result = document.getElementById("result");
// The equation is A = p *[[1 + (r/n)] ^ nt]
A = (p* Math.pow((1 + (r/(n*100))), (n*t)));
// tofixed is used for rounding the amount with two decimal places. result.innerHTML = "the total amount is " + A.tofixed(2);
result.innerHTML += "<br> the interest is " + (A.to Fixed(2) - p).toFixed(2);
}
</script>
<style>
div
{
display: table-row;
}
lable, input
{
display: table-cell;
}
</style>
</head>
<body>
<h1>compound interest</h1>
<div> <label>Amount: </label> <input id="p"> </div>
<div> <label>Rate (%): </label> <input id="r"> </div>
<div> <label>No. of Years: </label> <input id="t"> </div>
<div> <label>Computing times per year: </label> <input id="n" value="1">
<button onclick="calculate()">calculate</button>
<p id="result"></p>
</body>
</html>