Javascript公式语法不起作用

Javascript公式语法不起作用,javascript,html,math,syntax,javascript-objects,Javascript,Html,Math,Syntax,Javascript Objects,我有以下公式,正在尝试将其转换为JavaScript: =(x*(y/120000)*(1+(y/120000))^(z))/((1+(y/120000))^z-1) 我已经使用了以下内容,但我认为语法不正确,但我无法找出原因 var price = ((parseInt(x.value)*(parseInt(y.value)/1200)*(Math.pow(1+parseInt(y.value)/12000)),parseInt(z.value))) / (Math.pow((1+(pars

我有以下公式,正在尝试将其转换为JavaScript:

=(x*(y/120000)*(1+(y/120000))^(z))/((1+(y/120000))^z-1)
我已经使用了以下内容,但我认为语法不正确,但我无法找出原因

var price = ((parseInt(x.value)*(parseInt(y.value)/1200)*(Math.pow(1+parseInt(y.value)/12000)),parseInt(z.value))) / (Math.pow((1+(parseInt(y.value)/1200),(parseInt(z.value)-1)));
我的整个表单脚本如下:

<form name="priceCalc" action="">
  <div align="center">
    <select name="loanamount" onchange="price();">
      <option value="130000">£130,000</option>
      <option value="160000">£160,000</option>
    </select>

    <select name="interestrate" onchange="price();">
      <option value="449">4.49%</option>
      <option value="500">5%</option>
    </select>

    <select name="numberpayments" onchange="price();">
      <option value="480">40yrs</option>
      <option value="360">30yrs</option>
    </select>

    <br>
    <div id="prices">Change items to see price</div>
  </div>
</form>

<script>
  function price() {
    var x = document.priceCalc.loanamount;
    var y = document.priceCalc.interestrate;
    var z = document.priceCalc.numberpayments;

    var price = ((parseInt(x.value)*(parseInt(y.value)/1200)*(Math.pow(1+parseInt(y.value)/12000)),parseInt(z.value))) / (Math.pow((1+(parseInt(y.value)/1200),(parseInt(z.value)-1)));

    document.getElementById("prices").innerHTML = 'Price: ' + price;
  }
</script>

£130,000
£160,000
4.49%
5%
40岁
30年

更改项目以查看价格 函数价格(){ var x=document.priceCalc.loanamount; var y=document.priceCalc.interestrate; var z=document.priceCalc.numberpayments; var价格=((parseInt(x.value)*(parseInt(y.value)/1200)*(Math.pow(1+parseInt(y.value)/12000)),parseInt(z.value))/(Math.pow(1+(parseInt(y.value)/1200),(parseInt(z.value)-1)); document.getElementById(“prices”).innerHTML='Price:'+Price; }
任何帮助都将不胜感激

谢谢

此外,在您的顶行中有
/120000
,但在您的计算中有
/1200

同样根据gillesc的建议:

var x = parseInt(x.value);
var y = parseInt(y.value);
var z = parseInt(z.value);
var price = ((x*(y/120000)*(Math.pow((1+y)/120000),z)) / (Math.pow((1+(y/120000),(z-1)))));
此外,在您的顶行中有
/120000
,但在您的计算中有
/1200

同样根据gillesc的建议:

var x = parseInt(x.value);
var y = parseInt(y.value);
var z = parseInt(z.value);
var price = ((x*(y/120000)*(Math.pow((1+y)/120000),z)) / (Math.pow((1+(y/120000),(z-1)))));
此外,在您的顶行中有
/120000
,但在您的计算中有
/1200

同样根据gillesc的建议:

var x = parseInt(x.value);
var y = parseInt(y.value);
var z = parseInt(z.value);
var price = ((x*(y/120000)*(Math.pow((1+y)/120000),z)) / (Math.pow((1+(y/120000),(z-1)))));
此外,在您的顶行中有
/120000
,但在您的计算中有
/1200

同样根据gillesc的建议:

var x = parseInt(x.value);
var y = parseInt(y.value);
var z = parseInt(z.value);
var price = ((x*(y/120000)*(Math.pow((1+y)/120000),z)) / (Math.pow((1+(y/120000),(z-1)))));
翻译成

var x = parseInt(x.value,10), 
    y = parseInt(y.value,10)/120000, 
    z = parseInt(z.value,10)*12; // from your comments


var price = ( x*y*Math.pow(1+y,z) ) / (Math.pow(1+y,z)-1);
document.getElementById("prices").innerHTML ='Monthly repayment: £' + price.toFixed(2);
这是你的密码

window.onload=function(){
document.priceCalc.loanamount.onchange=价格;
document.priceCalc.interestrate.onchange=价格;
document.priceCalc.numberpayments.onchange=价格;
}
函数价格(){
var x=parseInt(document.priceCalc.loanamount.value,10);
var y=parseInt(document.priceCalc.interestrate.value,10)/12000;
var z=parseInt(document.priceCalc.numberpayments.value,10)*12;
var还款=(x*y*数学功率(1+y,z))/(数学功率(1+y,z)-1);
console.log(x,y,z,x*y*Math.pow(1+y,z),(Math.pow(1+y,z)-1),还款)
document.getElementById(“价格”).innerHTML=‘每月还款:£’+isFinite(还款)和&!isNaN(还款)和还款!=数字。正无穷大?还款。toFixed(2):‘0.00’;
}

请选择
£130,000
£160,000
请选择
4.49%
5%
请选择
40岁
30年

更改项目以查看价格
翻译成

var x = parseInt(x.value,10), 
    y = parseInt(y.value,10)/120000, 
    z = parseInt(z.value,10)*12; // from your comments


var price = ( x*y*Math.pow(1+y,z) ) / (Math.pow(1+y,z)-1);
document.getElementById("prices").innerHTML ='Monthly repayment: £' + price.toFixed(2);
这是你的密码

window.onload=function(){
document.priceCalc.loanamount.onchange=价格;
document.priceCalc.interestrate.onchange=价格;
document.priceCalc.numberpayments.onchange=价格;
}
函数价格(){
var x=parseInt(document.priceCalc.loanamount.value,10);
var y=parseInt(document.priceCalc.interestrate.value,10)/12000;
var z=parseInt(document.priceCalc.numberpayments.value,10)*12;
var还款=(x*y*数学功率(1+y,z))/(数学功率(1+y,z)-1);
console.log(x,y,z,x*y*Math.pow(1+y,z),(Math.pow(1+y,z)-1),还款)
document.getElementById(“价格”).innerHTML=‘每月还款:£’+isFinite(还款)和&!isNaN(还款)和还款!=数字。正无穷大?还款。toFixed(2):‘0.00’;
}

请选择
£130,000
£160,000
请选择
4.49%
5%
请选择
40岁
30年

更改项目以查看价格
翻译成

var x = parseInt(x.value,10), 
    y = parseInt(y.value,10)/120000, 
    z = parseInt(z.value,10)*12; // from your comments


var price = ( x*y*Math.pow(1+y,z) ) / (Math.pow(1+y,z)-1);
document.getElementById("prices").innerHTML ='Monthly repayment: £' + price.toFixed(2);
这是你的密码

window.onload=function(){
document.priceCalc.loanamount.onchange=价格;
document.priceCalc.interestrate.onchange=价格;
document.priceCalc.numberpayments.onchange=价格;
}
函数价格(){
var x=parseInt(document.priceCalc.loanamount.value,10);
var y=parseInt(document.priceCalc.interestrate.value,10)/12000;
var z=parseInt(document.priceCalc.numberpayments.value,10)*12;
var还款=(x*y*数学功率(1+y,z))/(数学功率(1+y,z)-1);
console.log(x,y,z,x*y*Math.pow(1+y,z),(Math.pow(1+y,z)-1),还款)
document.getElementById(“价格”).innerHTML=‘每月还款:£’+isFinite(还款)和&!isNaN(还款)和还款!=数字。正无穷大?还款。toFixed(2):‘0.00’;
}

请选择
£130,000
£160,000
请选择
4.49%
5%
请选择
40岁
30年

更改项目以查看价格
翻译成

var x = parseInt(x.value,10), 
    y = parseInt(y.value,10)/120000, 
    z = parseInt(z.value,10)*12; // from your comments


var price = ( x*y*Math.pow(1+y,z) ) / (Math.pow(1+y,z)-1);
document.getElementById("prices").innerHTML ='Monthly repayment: £' + price.toFixed(2);
这是你的密码

window.onload=function(){
document.priceCalc.loanamount.onchange=价格;
document.priceCalc.interestrate.onchange=价格;
document.priceCalc.numberpayments.onchange=价格;
}
函数价格(){
var x=parseInt(document.priceCalc.loanamount.value,10);
var y=parseInt(document.priceCalc.interestrate.value,10)/12000;
var z=parseInt(document.priceCalc.numberpayments.value,10)*12;
var还款=(x*y*数学功率(1+y,z))/(数学功率(1+y,z)-1);
console.log(x,y,z,x*y*Math.pow(1+y,z),(Math.pow(1+y,z)-1),还款)
document.getElementById(“价格”).innerHTML=‘每月还款:£’+isFinite(还款)和&!isNaN(还款)和还款!=数字。正无穷大?还款。toFixed(2):‘0.00’;
}

请选择
£130,000
£160,000
请选择
4.49%
5%
请选择
40岁
30年

更改项目以查看价格
请尝试以下更新公式:-

  var price = ((parseInt(x.value) * (parseInt(y.value) / 1200) * (Math.pow(((parseInt(1) + parseInt(y.value) / 12000)), parseInt(z.value)))) / (Math.pow((parseInt(1) + (parseInt(y.value) / 1200)), (parseInt(z.value) - 1))));

请尝试以下更新的公式:-

  var price = ((parseInt(x.value) * (parseInt(y.value) / 1200) * (Math.pow(((parseInt(1) + parseInt(y.value) / 12000)), parseInt(z.value)))) / (Math.pow((parseInt(1) + (parseInt(y.value) / 1200)), (parseInt(z.value) - 1))));

请尝试以下更新的公式:-

  var price = ((parseInt(x.value) * (parseInt(y.value) / 1200) * (Math.pow(((parseInt(1) + parseInt(y.value) / 12000)), parseInt(z.value)))) / (Math.pow((parseInt(1) + (parseInt(y.value) / 1200)), (parseInt(z.value) - 1))));
请tr