Skip to content

Commit b8370e3

Browse files
Merge pull request #1786 from ak-sh-at/loan
Loan Calculator Modified
2 parents 798dfb0 + 8620c03 commit b8370e3

1 file changed

Lines changed: 36 additions & 1 deletion

File tree

Projects/Loan-calculator/loancalculator.js

Lines changed: 36 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,11 +2,46 @@ function computeLoan(){
22
const amount = document.querySelector('#amount').value;
33
const interest_rate = document.querySelector('#interest_rate').value;
44
const months = document.querySelector('#months').value;
5+
if(amount<0&&interest_rate<0&&months<0)
6+
{
7+
alert("Please enter positive Loan amount , positive Interest Rate and positive number of months!");
8+
return;
9+
}
10+
if(amount<0 && interest_rate<0)
11+
{
12+
alert("Please enter positive Loan amount and positive Interest rate!");
13+
return;
14+
}
15+
if(amount<0 && months<0)
16+
{
17+
alert("Please enter positive Loan amount and positive number of months!");
18+
return;
19+
}
20+
if(interest_rate<0&&months<0)
21+
{
22+
alert("Please enter positive Interest Rate and positive number of months!");
23+
return;
24+
}
25+
if(amount<0)
26+
{
27+
alert("Please enter positive Loan amount!");
28+
return;
29+
}
30+
if(interest_rate<0)
31+
{
32+
alert("Please enter positive Interest Rate!");
33+
return;
34+
}
35+
if(months<0)
36+
{
37+
alert("Please enter positive number of months!");
38+
return;
39+
}
540
const interest = (amount * (interest_rate * 0.01)) / months;
641
let payment = ((amount / months) + interest).toFixed(2); //calculate monthly payment
742

843
//regedit to add a comma after every three digits
944
payment = payment.toString().replace(/\B(?=(\d{3})+(?!\d))/g, ","); //\B looks for a word boundary, ? says what to look for, \d looks for 3 digits in a row
1045
document.querySelector('#payment').innerHTML = `Monthly Payment = ${payment}`
11-
document.getElementById("payment").style.color = "white";
46+
document.getElementById("payment").style.color = "black";
1247
}

0 commit comments

Comments
 (0)