forked from bjssacademy/js-clean-code-workalong
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathint-clean-5.js
More file actions
20 lines (17 loc) · 716 Bytes
/
int-clean-5.js
File metadata and controls
20 lines (17 loc) · 716 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
function calculateInterest(principal, interestRate, years) {
const amount = principal * growthRate(interestRate, years);
const interest = amount - principal;
return roundedToTwoDecimalPlaces();
function roundedToTwoDecimalPlaces() {
return parseFloat(interest.toFixed(2));
}
function growthRate(interestRate, years) {
const growthAsDecimal = 1 + (interestRate / 100)
return Math.pow(growthAsDecimal, years)
}
}
let principal = 1000;
let interestRate = 5;
let years = 10;
let interest = calculateInterest(principal, rate, years);
console.log("The interest earned on $" + principal + " at an annual rate of " + rate + "% for " + years + " years is $" + interest);