Day              Approiximate Population
1                                   2

2                                   2.6

3                                   3.38

4                                   4.39

5                                   5.71

6                                   7.42

7                                   9.65

8                                   12.54

9                                   16.31

10                                 21.20

我的代码没有输出相同的“近似人口”。我哪里做错了?
这是我的代码:
    var NumOfOrganisms = 2;
    var DailyIncrease = .30;
    var NumOfDays;

    for(NumOfDays = 1; NumOfDays <= 10; NumOfDays++){
        calculation(NumOfOrganisms, DailyIncrease, NumOfDays);
    }

    function calculation(organisms, increase, days){
        var calculation = (organisms * increase) + days;
        console.log("increase is " + calculation);
    }

最佳答案

您没有考虑不断变化的人口。

var NumOfOrganisms = 2;
var DailyIncrease = .30;
var NumOfDays;

console.log('initial population', NumOfOrganisms);

for(NumOfDays = 2; NumOfDays <= 10; NumOfDays++) {
  NumOfOrganisms = (NumOfOrganisms * DailyIncrease) + NumOfOrganisms;
  console.log('increase is', NumOfOrganisms);
}

09-18 15:14