File tree Expand file tree Collapse file tree 1 file changed +13
-1
lines changed Expand file tree Collapse file tree 1 file changed +13
-1
lines changed Original file line number Diff line number Diff line change @@ -19,7 +19,19 @@ <h3>Loan Calculator</h3>
19
19
< p > Months to Pay:
20
20
< input type ="number " value ="1 " id ="months " min ="0 " onchange ="calculateLoan() "> </ p >
21
21
< h2 id ="payment "> </ h2 > </ div >
22
- < script src ="script.js "> </ script >
22
+ < script src ="script.js ">
23
+ function calculateLoan ( ) {
24
+ const amount = document . querySelector ( "#amount" ) . value ;
25
+ const interestRate = document . querySelector ( "#interest" ) . value ;
26
+ const months = document . querySelector ( "#months" ) . value ;
27
+ const monthlyRate = ( interestRate ) / ( 12 * 100 ) ;
28
+ const onePlusR = Math . pow ( 1 + monthlyRate , months ) ;
29
+ const den = onePlusR - 1 ;
30
+ const emi = ( amount * monthlyRate * ( onePlusR / den ) ) . toFixed ( 2 ) ;
31
+ const totalPay = ( emi * months ) . toFixed ( 2 ) ;
32
+ document . querySelector ( "#payment" ) . innerHTML = `EMI: ₹ ${ emi } <br><br> Total Payment: ₹${ totalPay } `
33
+ }
34
+ </ script >
23
35
</ body >
24
36
25
37
</ html >
You can’t perform that action at this time.
0 commit comments