File tree Expand file tree Collapse file tree 4 files changed +8
-4
lines changed Expand file tree Collapse file tree 4 files changed +8
-4
lines changed Original file line number Diff line number Diff line change @@ -4,9 +4,13 @@ function calculateLoan(){
4
4
const interestRate = document . querySelector ( "#interest" ) . value ;
5
5
const months = document . querySelector ( "#months" ) . value ;
6
6
7
- const interest = ( amount * ( interestRate * 0.01 ) ) / months ;
8
- const payment = ( ( amount / months ) + interest ) . toFixed ( 2 ) ;
7
+ const monthlyRate = ( interestRate ) / ( 12 * 100 ) ;
8
+ const onePlusR = Math . pow ( 1 + monthlyRate , months ) ;
9
+ const den = onePlusR - 1 ;
9
10
10
- document . querySelector ( "#payment" ) . innerHTML = `EMI: ₹ ${ payment } `
11
+ const emi = ( amount * monthlyRate * ( onePlusR / den ) ) . toFixed ( 2 ) ;
12
+ const totalPay = ( emi * months ) . toFixed ( 2 ) ;
13
+
14
+ document . querySelector ( "#payment" ) . innerHTML = `EMI: ₹ ${ emi } <br><br> Total Payment: ₹${ totalPay } `
11
15
12
16
}
Original file line number Diff line number Diff line change 5
5
.container {
6
6
width : 400px ;
7
7
height : 450px ;
8
- background-color : # ff1d58 ;
8
+ background-color : # ff4a7a ;
9
9
position : absolute;
10
10
top : 50% ;
11
11
left : 50% ;
You can’t perform that action at this time.
0 commit comments