Wednesday, June 30, 2021

Simple Interest Calculator in JavaScript

 A simple interest calculator in JavaScript I wrote a long time ago while teaching JavaScript programming in one of the colleges here in the Philippines.

I am currently accepting programming work, IT projects, school and application development, programming projects, thesis and capstone projects, IT consulting work, computer tutorials, and web development work kindly contact me at the following email address for further details.  If you want to advertise on my website, kindly contact me also at my email address also. Thank you.

My email address is jakerpomperada@gmail.com and jakerpomperada@yahoo.com

My mobile number here in the Philippines is 09173084360.






Program Listing

index.htm

<html>
<style>
body,p {

  font-family:arial;
  font-size:16px;
  font-weight:bolder;
 }
 
    .container {
        width: 450px;
        clear: both;
    }
    .container input {
        width: 100%;
        clear: both;
    }

    </style>
<div class="container">
<body>
<h3> Simple Interest Calculator in JavaScript </h3>
<br/>Principal (P): Php
<input type="text" id="principal" name="principal">
<br>
<br/> Rate (R):
<input type="text" id="rate" name="rate">
<br>
<br/> Time (t):
<input type="text" id="time" name="time">
<br>
<br>
<button onclick="compute_interest()">Compute Interest</button>
<br><br>
<p id="demo"></p>

</div>
<script>
function Commas(n) {
    var parts=n.toString().split(".")
    return parts[0].replace(/\B(?=(\d{3})+(?!\d))/g, ",") + (parts[1] ? "." + parts[1] : "");
}
  function compute_interest() {
    var  principal = document.getElementById("principal").value;
var  rate = document.getElementById("rate").value;
var  time = document.getElementById("time").value;
     rate2 = parseFloat(rate)/100;
amount_interest = parseFloat(principal) * (1+ (parseFloat(rate2)*time));
     
amt =amount_interest.toFixed(2);
display = Commas(amt);
results ="Amount to be paid is Php " + display+".";
     
      document.getElementById("demo").innerHTML = results;
  }
</script>
</body>
</html>


No comments:

Post a Comment