-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathscript.js
More file actions
26 lines (21 loc) · 1.05 KB
/
Copy pathscript.js
File metadata and controls
26 lines (21 loc) · 1.05 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
const principalBox = document.querySelector("#principal");
const aprSlider = document.querySelector("#apr");
const aprText = document.querySelector("#aprText");
const yearsBox = document.querySelector("#years");
const periodSelect = document.querySelector("#period");
const accumulatedOutput = document.querySelector("#accumulated");
const amountOutput = document.querySelector("#amount");
aprSlider.addEventListener("input", () => {
aprText.textContent = aprSlider.value;
});
function calculate() {
const principal = parseFloat(principalBox.value);
const apr = parseFloat(aprSlider.value) / 100;
const years = parseFloat(yearsBox.value);
const period = parseInt(periodSelect.value);
const amount = principal * Math.pow(1 + apr / period, period * years);
const interest = amount - principal;
accumulatedOutput.textContent = interest.toFixed(2); // Limit the output to 2 decimal places
amountOutput.textContent = amount.toFixed(2); // Limit the output to 2 decimal places
}
document.querySelector("#calculateButton").addEventListener("click", calculate);