Write a program that predicts the approximate size of a population of organisms. Use the following data:
- Starting number of organisms: 2
- Average daily increase: 30%
- Number of days to multiply: 10
The program should display the following table of data:
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
My code is not outputting the same Approximate Population. Where did I go wrong? Here is my code:
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);
}
You do not take in consideration the evolving population.
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);
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With