Created
February 28, 2018 14:34
-
-
Save aledwassell/c2be23a0dadcaeb190b41a12f0ddafba to your computer and use it in GitHub Desktop.
In a small town the population is p0 = 1000 at the beginning of a year. The population regularly increases by 2 percent per year and moreover 50 new inhabitants per year come to live in the town. How many years does the town need to see its population greater or equal to p = 1200 inhabitants?
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
function nbYear(p0, percent, aug, p) { | |
// your code | |
let yearsGrown = 0; | |
let popNow = p0; | |
let amountGrown = ((popNow / 100) * percent) + 50; | |
while(popNow < 1200){ | |
popNow += amountGrown; | |
yearsGrown++; | |
} | |
console.log('population now ', popNow) | |
console.log('how many years to get to that population ', yearsGrown) | |
console.log('amount grown each year ', amountGrown) | |
} | |
nbYear(1000, 2, null, null) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment