Home > front end >  Js loan calculator how to convert the jquery code
Js loan calculator how to convert the jquery code

Time:10-28

The function house () {
This. The num=0,//loan amount
This. The year=0,//loan fixed number of year
Enclosing yearRate=0,//apr
Enclosing type=0,//loan
This. The output={
Amount: 0,//monthly month for
Zonglixi: 0,//total interest
Hkprice: 0,//reimbursement amount
}

//calculation method of principal and interest waiting for the forehead
This. Benxi=function () {
Var month=parseInt (this year) * 12;//reimbursement months
Var monthRate=parseFloat (enclosing yearRate)/12;//month for
Var dknum=parseFloat (enclosing num) * 10000;//loan amount
Var amount=(monthRate dknum * * math.h pow ((1 + monthRate), month))/(math.h pow ((1 + monthRate), month) - 1)//monthly month for
Var zonglixi=month * amount - dknum;//=total interest repayment months * monthly month for the loan amount
-Var hkprice=zonglixi + dknum;//=total interest repayment amount + loan amount

This. The output. The amount=amount. ToFixed (2)
This. The output. Zonglixi=zonglixi. ToFixed (2)
This. The output. Hkprice=hkprice. ToFixed (2)
}

This. Benjin=function () {
Var month=parseInt (this year) * 12;//reimbursement months
Var monthRate=parseFloat (enclosing yearRate)/12;//month for
Var dknum=parseFloat (enclosing num) * 10000;//loan amount
Var everymonth=dknum/month;//monthly loan amount/months reimbursement should also amount=
Var amount=dknum/month + dknum * monthRate;
Var zonglixi=((everymonth + dknum * monthRate) + dknum/month * (1 + monthRate))/2 * month - dknum;
Var hkprice=zonglixi + dknum;

This. The output. The amount=amount. ToFixed (2)
This. The output. Zonglixi=zonglixi. ToFixed (2)
This. The output. Hkprice=hkprice. ToFixed (2)
}
}

Var house=new house ();

The function getinput () {
Var dknum=document. GetElementById (' dknum). The value;
Var year=document. GetElementById (' yearx). The value;
Var yearlilv=document. GetElementById (' box2.) the value;
Var Obj=document. GetElementById (' box '). The value;

House. Num=dknum;
House. Year=year;
House. YearRate=yearlilv;
House. Type=Obj.
Return true
}

The function showResult () {
Var result=[house. The output amount, house. The output. The zonglixi, house. The output. The hkprice]
Var text=[' monthly ', 'total interest', 'total payments]
Var HTML='& lt; Tr> Project & lt;/th> The amount & lt;/th> '
for(var i=0; iVar Otable=document. GetElementById (' jg);
HTML +='& lt; Tr> '+ text [I] +' : & lt;/td> '+ result [I] +' & lt;/td> '
Otable. InnerHTML=HTML;
}
}

The function result () {
If (getinput ()) {
If (house. Type==0) {
House. Benxi ();
}
If (house. Type==1) {
House. Benjin ();
}
ShowResult ();
}

}



<body>



Loan amount: & lt;/span>


Loan fixed number of year: & lt;/span>


Interest: & lt;/span>








CodePudding user response:

novice for help!!
  • Related