为了账号安全,请及时绑定邮箱和手机立即绑定

Google App Script If Condition 没有给出答案

Google App Script If Condition 没有给出答案

鸿蒙传说 2023-04-20 16:34:44
我试图添加一个 if 条件。条件一如果预付款低于35%价格则"Your downpayment should be above 35% of the price"条件二如果预付款高于100%价格则"your downpayment should be below 100% of the price"条件三,如果首付款在 35%-100% 之间,则计算一下。答案在我下面的代码中不起作用,我哪里出错了? if(parseInt(downPayment) < 0.35*parseInt(vprice) || parseInt(downPayment) = parseInt(vprice)) {    document.getElementById("month").innerHTML = "Your downpayment should be minimum 35% of the price - "  +" (↑"+ nf.format((Math.round(vprice*0.35))) +")";    }      else if(parseInt(downPayment) > parseInt(vprice)) {    document.getElementById("month").innerHTML = "Your downpayment should be below 100% of the price - "  +" (↑"+ nf.format((Math.round(vprice*0.100))) +")";    }    else {    document.getElementById("month").innerHTML = " 1st Year Monthly Rental: "+ nf.format((Math.round(month))) + "<br>2nd Year Monthly Rental: " +  nf.format((Math.round(month2))) + "<br>3rd Year Monthly Retal:"+  nf.format((Math.round(month3))) ;  google.script.run.userClicked({    vprice,    downPayment,    rate,    period,    month  });  //sending to HTML by ID  document.getElementById("subL").innerHTML = "Sub Loan - "+  nf.format((Math.round(subL)));  document.getElementById("YearBulk1").innerHTML = "1st Year End Bulk Payment - "+ nf.format((Math.round(YearBulk1))); document.getElementById("YearBulk2").innerHTML = "2nd Year End Bulk Payment - "+ nf.format((Math.round(YearBulk2))); document.getElementById("YearBulk3").innerHTML = "3rd Year End Bulk Payment - "+ nf.format((Math.round(YearBulk3)));      }
查看完整描述

1 回答

?
潇潇雨雨

TA贡献1833条经验 获得超4个赞

解释:

  • 你在第一个陈述中有一个错字if;它应该==代替=但你也可以通过使用简化表达式<=

  • 您必须放在条件document.getElementById("month").innerHTML之外if,否则其余元素将不会发送到网页。

  • 我还使用模板文字来简化您的表达式并使其更适合未来。


解决方案:

if(parseInt(downPayment) <= 0.35*parseInt(vprice) ) {

  var resm = `Your downpayment should be minimum 35% of the price - (↑ ${nf.format((Math.round(vprice*0.35)))})`;

  }

  

  

  else if(parseInt(downPayment) > parseInt(vprice)) {

    var resm = `Your downpayment should be below 100% of the price - (↑ ${nf.format((Math.round(vprice*0.100)))})`;

  }

  

  else {

var resm = `1st Year Monthly Rental: ${nf.format((Math.round(month)))} <br>2nd Year Monthly Rental: ${nf.format((Math.round(month2)))} <br>3rd Year Monthly Retal: ${nf.format((Math.round(month3)))}`;

  }



  document.getElementById("month").innerHTML = resm;

  google.script.run.userClicked({

    vprice,

    downPayment,

    rate,

    period,

    month

  })


  //sending to HTML by ID

  document.getElementById("subL").innerHTML = "Sub Loan - "+  nf.format((Math.round(subL)));

  document.getElementById("YearBulk1").innerHTML = "1st Year End Bulk Payment - "+ nf.format((Math.round(YearBulk1)));

 document.getElementById("YearBulk2").innerHTML = "2nd Year End Bulk Payment - "+ nf.format((Math.round(YearBulk2)));

 document.getElementById("YearBulk3").innerHTML = "3rd Year End Bulk Payment - "+ nf.format((Math.round(YearBulk3)));



查看完整回答
反对 回复 2023-04-20
  • 1 回答
  • 0 关注
  • 69 浏览
慕课专栏
更多

添加回答

举报

0/150
提交
取消
意见反馈 帮助中心 APP下载
官方微信