Skip to content

Commit

Permalink
Adding Loan Calculator
Browse files Browse the repository at this point in the history
  • Loading branch information
kalashvasaniya committed Apr 4, 2022
1 parent 6261f2d commit f991d63
Show file tree
Hide file tree
Showing 3 changed files with 59 additions and 0 deletions.
1 change: 1 addition & 0 deletions 98 - Loan Calculator/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
# loan-calculator
36 changes: 36 additions & 0 deletions 98 - Loan Calculator/index.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
<!DOCTYPE html>
<html lang="en">

<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<meta http-equiv="X-UA-Compatible" content="ie=edge">
<link rel="stylesheet" href="loancalculator.css">
<title>Loan Calculator</title>
</head>

<body>
<div id="loancal">
<h1>Loan Calculator</h1>
<p>Loan Amount: $<input id="amount" type="number" min="1" max="5000000" onchange="computeLoan()"></p>
<p>Interest Rate: %<input id="interest_rate" min="0" max="100" value="10" step=".1" onchange="computeLoan()">
</p>
<p>Months to Pay: <input id="months" type="number" min="1" max="300" value="1" step="1"
onchange="computeLoan()"></p>
<h2 id="payment"></h2>
</div>
<script>
function computeLoan() {
const amount = document.querySelector('#amount').value;
const interest_rate = document.querySelector('#interest_rate').value;
const months = document.querySelector('#months').value;
const interest = (amount * (interest_rate * 0.01)) / months;
let payment = ((amount / months) + interest).toFixed(2);

payment = payment.toString().replace(/\B(?=(\d{3})+(?!\d))/g, ",");
document.querySelector('#payment').innerHTML = `Monthly Payment = ${payment}`
}
</script>
</body>

</html>
22 changes: 22 additions & 0 deletions 98 - Loan Calculator/loancalculator.css
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
#loancal {
padding-top: 15px;
padding-left: 75px;
width: 375px;
height: 295px;
background-color:#000;
color: #fff;
}

#months, #amount, #interest_rate{
width: 175px;
height: 20px;

}

#interest_rate {
margin-left: 2px;
}

h1 {
font-size:40px;
}

0 comments on commit f991d63

Please sign in to comment.