Showing posts with label interest solver in javascript. Show all posts
Showing posts with label interest solver in javascript. Show all posts

Tuesday, September 30, 2014

Compound Interest Solver in JavaScript

One of my favorite scripting programming language is JavaScript in this program I wrote a simple Compound Interest Solver that will solve for the interest rate for the loan made by the person. The code is very simple and easy to understand, I'm using notepad++ as my test editor in writing this program.

If you have some questions about my work please send me an email at jakerpomperada@gmail.com and jakerpomperada@yahoo.com.

Thank you very much.


Sample Output of Our Program


Program Listing

<!-- Written By: Jake R. Pomperada, MAED-IT  2014-->
<HTML>
<HEAD>
<SCRIPT LANGUAGE="JavaScript">
<!-- Begin
var princ;
var ratepc;
var years;
var rate;
var power;
function calcAmt(frm) {
princ = eval(frm.pr.value);
ratepc = eval(frm.rt.value);
years = eval(frm.yr.value);
rate = ratepc / 100;
power = Math.pow((1 + rate), years);
frm.amt.value = Math.round(princ * power * 100) / 100;
frm.inter.value = Math.round((frm.amt.value - princ) * 100) / 100;
}
function checkInput(frm) {
if (rate == 0 || rate > .3) {
window.alert ("Are you sure that the interest rate is " + ratepc +"%?");
frm.rt.focus();
}
if (years == 0 || years > 30) {
window.alert ("Are you sure that the term is " + years + " years?");
frm.yr.focus();
   }
}
//  End -->
</script>

</HEAD>


<BODY BGCOLOR="LIGHTGREEN">

<center>
<hr>
<h1> <font face="comic sans ms"> COMPOUND INTEREST SOLVER  </h1>
<hr>
<br> <br>
<font size=5>
<form method=get name=frm>
Principal <input type=text name=pr size=10 maxlength=10 onChange=calcAmt(this.form)>
Rate <input type=text name=rt size=6 maxlength=6 onChange=calcAmt(this.form)>
Years <input type=text name=yr size=5 maxlength=5 onChange=calcAmt(this.form)>
<br>
<br>
<input type=button name=calc value="Calculate" size=10 onClick=checkInput(this.form); calcAmt(this.form);>
<input type=reset value="Clear">
<br>
<br>
Amount <input type=text name=amt size=10>
Interest <input type=text name=inter size=10>
</form>
</font>
</font>
</center>
</body>
</html>