Table of Contents
Best JavaScript program to calculate compound interest
It is best and simple Javascript program to calculate compound interest.
Output: Program to calculate Compound Interest in Javascript
JavaScript code to calculate Compound Interest
HTML code
<!DOCTYPE html> <html> <head> <meta charset="utf-8"> <title>Compound Interest - ITVoyagers</title> </head> <body> <label>Principle</label><br> <input type="text" name="val" id="principle" placeholder="Principle"> <br> <label>Rate of Interest</label><br> <input type="text" name="val" id="roi" placeholder="Rate of the interest"> <br> <label>Years</label><br> <input type="text" name="val" id="years" placeholder="Years"> <br> <!-- itvoyagers.in --> <button id="calculate_button" onclick="countCI()">Calculate</button> <br> <div id="outputdiv"> <label>Compound Interest is : <span id="outputspan"></span></label> </div> <script type="text/javascript" src="compoundinterest.js"></script> <!-- itvoyagers.in --> </body> </html>
Javascript code (compoundinterest.js)
var principle = document.getElementById("principle"); var roi = document.getElementById("roi"); var years = document.getElementById("years"); var outputspan = document.getElementById("outputspan"); //itvoyagers.in function countCI() { p = parseFloat(principle.value); r = parseFloat(roi.value); t = parseFloat(years.value); ci = p*(Math.pow((1+r/100),t)); outputspan.innerHTML = ci; }