Table of Contents
Best Javascript program to calculate simple interest
It is best and simple Javascript program to calculate simple interest.
Formula to calculate simple interest is:
Simple interest = (P x N x R)/100
P : Principle amount
N : Number of years
R : Rate of interest
Output: Write a program to calculate simple interest using JavaScript
Javascript program to calculate simple interest
HTML code
<!DOCTYPE html> <html> <head> <meta charset="utf-8"> <title>Simple Interest - ITVoyagers</title> </head> <body> <label>Principle</label><br> <input type="text" id="principle" placeholder="Principle"> <br> <label>Years</label><br> <input type="text" id="years" placeholder="Years"> <br> <label>Rate of Interest(%)</label><br> <input type="text" id="roi" placeholder="Rate of the interest(%)"> <br> <!-- itvoyagers.in --> <button id="calculate_button" onclick="countSI()">Calculate</button> <br> <div id="outputdiv"> <label>Simple Interest is : <span id="outputspan"></span></label> </div> <script type="text/javascript" src="simpleinterest.js"></script> <!-- itvoyagers.in --> </body> </html>
Javascript code (simpleinterest.js)
var principle = document.getElementById("principle"); var roi = document.getElementById("roi"); var years = document.getElementById("years"); var outputspan = document.getElementById("outputspan"); //itvoyagers.in function countSI() { p = parseFloat(principle.value); n = parseFloat(years.value); r = parseFloat(roi.value); si = (p*n*r)/100; outputspan.innerHTML = si; }