File tree 3 files changed +28
-19
lines changed
3 files changed +28
-19
lines changed Original file line number Diff line number Diff line change 4
4
< meta charset ="UTF-8 ">
5
5
< meta http-equiv ="X-UA-Compatible " content ="IE=edge ">
6
6
< meta name ="viewport " content ="width=device-width, initial-scale=1.0 ">
7
- < title > loan calculator </ title >
7
+ < title > Loan Calculator </ title >
8
8
< link rel ="stylesheet " href ="style.css ">
9
9
</ head >
10
10
< body >
11
11
< div class ="container ">
12
- < h1 > loan calculator </ h1 >
13
- < p > loan amount $
14
- < input onchange ="calculateLoan() " class ="input " type ="number " id ="amount " min ="1 " max ="500000 ">
12
+ < h1 > Loan Calculator </ h1 >
13
+ < p > Loan Amount $
14
+ < input onchange ="calculateLoan() " class ="input " type ="number " id ="loan- amount " min ="1 " max ="500000 " value =" 10000 ">
15
15
</ p >
16
- < p > interest rate % < input onchange ="calculateLoan() " class ="input " type ="number " id ="interest_rate " min ="0 " max ="100 " step =".1 ">
16
+ < p > Interest Rate %
17
+ < input onchange ="calculateLoan() " class ="input " type ="number " id ="interest-rate " min ="0 " max ="100 " value ="10 " step =".1 ">
17
18
</ p >
18
- < p > month to pay
19
- < input onchange ="calculateLoan() " class ="input " type ="number " id ="months " min ="1 " max ="500000 ">
19
+ < p > Months to pay
20
+ < input onchange ="calculateLoan() " class ="input " type ="number " id ="months-to-pay " min ="6 " max ="48 " value =" 12 ">
20
21
</ p >
21
- < p id ="payment "> monthly payment: </ p >
22
+ < p class =" payment " id ="payment "> Monthly Payment: </ p >
22
23
</ div >
24
+
23
25
< script src ="index.js "> </ script >
24
26
</ body >
25
- </ html >
27
+ </ html >
Original file line number Diff line number Diff line change 1
1
function calculateLoan ( ) {
2
- const amount = document . getElementById ( "amount" ) . value
3
- const interest_rate = document . getElementById ( "interest_rate" ) . value
4
- const months = document . getElementById ( "months" ) . value
5
- const interest = ( amount * ( interest_rate * .01 ) ) / months
2
+ loanAmountValue = document . getElementById ( "loan-amount" ) . value ;
6
3
7
- const payment = ( amount / months + interest ) . toFixed ( 2 )
4
+ interestRateValue = document . getElementById ( " interest-rate" ) . value ;
8
5
9
- document . getElementById ( "payment " ) . innerHTML = `monthly payment: ${ payment } `
6
+ MonthsToPayValue = document . getElementById ( "months-to-pay " ) . value ;
10
7
8
+ interest = ( loanAmountValue * ( interestRateValue * 0.01 ) ) / MonthsToPayValue ;
11
9
12
- }
10
+ monthlyPayment = ( loanAmountValue / MonthsToPayValue + interest ) . toFixed ( 2 ) ;
11
+
12
+ document . getElementById (
13
+ "payment"
14
+ ) . innerHTML = `Monthly Payment: ${ monthlyPayment } ` ;
15
+ }
Original file line number Diff line number Diff line change 9
9
}
10
10
11
11
.container {
12
- background-color : darkcyan;
12
+ background : darkcyan;
13
13
color : aliceblue;
14
14
padding : 20px ;
15
15
border-radius : 10px ;
16
-
17
16
}
18
17
19
18
.input {
20
19
width : 100% ;
21
- height : 100% ;
20
+ font-size : 20px ;
21
+ height : 30px ;
22
+ }
23
+
24
+ .payment {
25
+ font-weight : 600 ;
22
26
font-size : 20px ;
23
27
}
You can’t perform that action at this time.
0 commit comments