forked from 0xvashishth/CalcHub
-
Notifications
You must be signed in to change notification settings - Fork 0
/
script.js
42 lines (33 loc) · 1.05 KB
/
script.js
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
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
const form = document.getElementById('form');
const principal = document.getElementById('principal');
const rate = document.getElementById('rate');
const time = document.getElementById('time');
const resultInterest = document.getElementById('resultInterest');
const resultAmount = document.getElementById('resultAmount');
const resultElement = document.getElementById('result');
let p = 0;
let r = 0;
let t = 0;
let interest = 0;
let amount = 0;
principal.addEventListener('input', (e) => {
resultElement.classList.add('hide');
})
const calculateInterest = () => {
p = parseFloat(principal.value);
r = parseFloat(rate.value);
t = parseFloat(time.value);
interest = ((p*r*t)/100);
resultInterest.innerText = `₹ ${interest.toFixed(2)}`;
}
const calculateAmount = () => {
amount = (p + interest);
resultAmount.innerText = `₹ ${amount.toFixed(2)}`;
}
console.log("form")
form.addEventListener('submit', (e) => {
e.preventDefault();
resultElement.classList.remove('hide');
calculateInterest();
calculateAmount();
})