在我的工作中,我试图弄清楚在拥有一百万美元之前,您必须保存指定金额的年数。
但是我的功能是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);
答案 0 :(得分:0)
两个函数都希望使用一个数字作为参数。但是,如果指定两个,它们将运行无误。
您似乎想用250000
而不是250
进行计算。
添加的逗号产生两个参数:250
和0
。