JS 04 – Best JavaScript program to calculate compound interest

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

Compound Interest - ITVoyagers

JavaScript code to calculate Compound Interest

HTML code

<!DOCTYPE html>
	<meta charset="utf-8">
	<title>Compound Interest - ITVoyagers</title>
	<input type="text" name="val" id="principle" placeholder="Principle">
	<label>Rate of Interest</label><br>
	<input type="text" name="val" id="roi" placeholder="Rate of the interest">
	<input type="text" name="val" id="years" placeholder="Years">
<!-- itvoyagers.in -->
	<button id="calculate_button" onclick="countCI()">Calculate</button>
	<div id="outputdiv">
		<label>Compound Interest is : <span id="outputspan"></span></label>
	<script type="text/javascript" src="compoundinterest.js"></script>
<!-- itvoyagers.in -->

Javascript code (compoundinterest.js)

var principle = document.getElementById("principle");
var roi = document.getElementById("roi");
var years = document.getElementById("years");
var outputspan = document.getElementById("outputspan");

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;

Connect with us on following platforms

Leave a Comment