为什么我的Javascript函数无法正常工作?

时间:2018-10-23 04:01:48

标签: javascript function

在我的工作中,我试图弄清楚在拥有一百万美元之前,您必须保存指定金额的年数。
但是我的功能是console.logging数以千计而不是几年。

//The function I have created.
function retirement(yearsTillPaid){

//Why does it not work right?
return function(millionDollarDream){
    var goalTo = 1000000;
    var baller = goalTo / millionDollarDream;
    var amount = millionDollarDream / baller;
    var howManyYears = goalTo / amount;
    console.log(howManyYears); 
     }
  }


  //calling my function
  var retirementUs = retirement(250,000);
  var retirementNk = retirement(1);
  var retirementAu = retirement(1);
  var retirementGermany = retirement(1);

  retirementUs(250,000);
  retirementNk(140,100);
  retirementAu(333,000);
  retirementGermany(50,000);

1 个答案:

答案 0 :(得分:0)

两个函数都希望使用一个数字作为参数。但是,如果指定两个,它们将运行无误。

您似乎想用250000而不是250进行计算。 添加的逗号产生两个参数:2500