My javascript output does not match the expected result. I do not know where I was wrong

Write a program that predicts the approximate size of a population of organisms. Use the following data:

  • Initial number of organisms: 2
  • Average daily growth: 30%
  • Number of days to multiply: 10

The program should display the following data table:

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 does not output the same approximate population. Where am I 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); } 
+5
source share
2 answers

You do not take into account the developing 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); } 
+2
source

should not calculate equal something more than organisms + (growth of organisms *)? And then, if you keep the current amount, you do not need to feed your function the number of days

+1
source

All Articles