我有一个带两个输入并运行三个功能的计算器。第一个函数使用两个输入,第二个函数从第一个函数和一个输入中返回。第三个函数从前两个函数返回并比较它们。
我无法将第一个函数的返回值放到第二个函数中。
//the user inputs two values (priorLoan,newLoan)
//this function makes the first calculation and that value is then further calculated in the next function
function refiCalc (priorLoan,newLoan) {
if (priorLoan>newLoan){
if (newLoan <= 100000) {
return Math.ceil(newLoan/1000)*2.5
}else if (newLoan <= 500000) {
return 250+Math.ceil((newLoan-100000)/1000)*2.25
}else if (newLoan <= 2000000) {
return 1150+Math.ceil((newLoan-500000)/1000)*2
}else{ return 4150+Math.ceil((newLoan-2000000)/1000)*1.5
}
}else{
if (priorLoan <= 100000) {
return Math.ceil(priorLoan/1000)*2.5
}else if (priorLoan <= 500000) {
return 250+Math.ceil((priorLoan-100000)/1000)*2.25
}else if (priorLoan <= 2000000) {
return 1150+Math.ceil((priorLoan-500000)/1000)*2
}else{ return 4150+Math.ceil((priorLoan-2000000)/1000)*1.5
}
}
}
//this part takes the value from the refiCalc and the value from the newLoan
function lenderRefiblend (newLoan,refiCalculator){
if (refiCalculator<0){
if (newLoan<=100000){
return Math.ceil(newLoan/1000)*5;
}else if((newLoan-100000)<=500000){
return 500+Math.ceil((newLoan-100000)/1000)*3.95;
}else if ((newLoan-500000)<=2000000) {
return 2080+Math.ceil((newLoan-500000)/1000)*2.65;
}else{
return 6055+Math.ceil((newLoan-2000000)/1000)*2;
}
}else if (refiCalculator<=250){
if ((refiCalculator/2.5)>0){
if ((newLoan-100000)>0){
return (100-(refiCalculator/2.5)*5)
}else{
return ((Math.ceil(newLoan/1000))-(refiCalculator/2.5))*5
}
}else{
return Math.ceil(newLoan/1000)*5
}
}else if (refiCalculator<=1150){
if (((refiCalculator-250)/2.25)>0){
if ((newLoan-500000)>0){
return (400-((refiCalculator-250)/2.25)*3.95)
}else{
return ((Math.ceil((newLoan-100000)/1000))-((refiCalculator-250)/2.25))*3.95
}
}else{
return Math.ceil(newLoan/1000)*3.95
}
}else if (refiCalculator<=4150){
if (((refiCalculator-1150)/2)>0){
if ((newLoan-2000000)>0){
return (1500-((refiCalculator-1150)/2)*2.65)
}else{
return ((Math.ceil((newLoan-500000)/1000))-((refiCalculator-1150)/2))*2.65
}
}else{
return Math.ceil(newLoan/1000)*2.65
}
}else{
return ((Math.ceil((newLoan-2000000)/1000))-((refiCalculator-4150)/1.5))*2
}
}
//in the end i want to combine the total of reficalc and lenderRefiblend
function refiPremium (refi,blend) {
if ((refi+blend)<200) {
return 200
}else{
return refi+blend
}
}
//what is stumping me is how I would go about putting the refiCalc return into my lenderRefiblend
function updateOutput(form){
var newLoan = parseInt(form.elements["new_loan_amount"].value);
var priorLoan = parseInt(form.elements ["prior_loan_amount"].value);
form.elements["premium_rate"].value = refiPremium(refiCalc(priorLoan,newLoan),lenderRefiblend(newLoan,refiCalc));
}
//--></script>
<form id="standardPremiumcalc">
<input name= "new_loan_amount" type="number" value="0">
<input name= "prior_loan_amount" type="number" value="0">
<input type=button name=calcnun value="Calculate" onClick="javascript:updateOutput(this.form)">
Value is: <input name= "premium_rate" type="number">
</form>
答案 0 :(得分:1)
您可以为此使用额外的变量......
var refiCalcResult = refiCalc(priorLoan, newLoan),
lenderRefiblendResult = lenderRefiblend(newLoan, refiCalcResult),
refiPremiumResult = refiPremium(refiCalcResult, lenderRefiblendResult);