This may seem like a stupid question but I just started learning javascript about a week ago. I decided to try and automate my homework with javascript but I can’t figure out how to do this. It works as follows:
You are calculating how many decades it takes for a population to reach a certain number.
We’ll make this simple and make the growth rate .20. The population will start at 50 and we want it to reach 100.
So far this is what I have:
function newPeople(start, growth) {
var a = start * growth;
var b = start + a;
var c = Math.round(b);
var d = c * growth;
var e = c + d;
var f = Math.round(e);
return f;
}
newPeople(50, .20);
You can see that it can be done manually by creating a new set of variables each time, but how do I automate that?
This should work: