gpt4 book ai didi

javascript - 在两个函数中调用变量时遇到问题

转载 作者:行者123 更新时间:2023-11-28 02:15:34 25 4
gpt4 key购买 nike

我有一个计算器,它接受两个输入并运行三个函数。第一个函数使用两个输入,第二个函数获取第一个函数和其中一个输入的返回值。第三个函数获取前两个函数的返回值并进行比较。

我无法将第一个函数的返回结果放入第二个函数中。

//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>

最佳答案

您可以为此使用额外的变量...

var refiCalcResult = refiCalc(priorLoan, newLoan),
lenderRefiblendResult = lenderRefiblend(newLoan, refiCalcResult),
refiPremiumResult = refiPremium(refiCalcResult, lenderRefiblendResult);

关于javascript - 在两个函数中调用变量时遇到问题,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/16454102/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com