forked from kishanrajput23/Java-Projects-Collections
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathCI.js
16 lines (13 loc) · 757 Bytes
/
CI.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
function calculateCompoundInterest() {
// Get input values
var principal = parseFloat(document.getElementById("principal").value);
var annualRate = parseFloat(document.getElementById("annualRate").value);
var compoundingFrequency = parseInt(document.getElementById("compoundingFrequency").value);
var years = parseInt(document.getElementById("years").value);
// Calculate compound interest
var amount = principal * Math.pow(1 + (annualRate / compoundingFrequency), compoundingFrequency * years);
// Round the result to two decimal places
amount = Math.round(amount * 100) / 100;
// Display the result
document.getElementById("result").innerHTML = "The final amount after " + years + " years is: $" + amount;
}