The function nb_year should return n number of entire years needed to get a population greater or equal to p.The given parameters are p0(original population), percent(percentage of increase), aug (inhabitants coming or leaving each year), p (population to surpass) i understand what the math is to get the result i just don't know what type of loop i should write to keep increasing the numbers. here is my current code
function nbYear(p0, percent, aug, p) {
var increaseInHab = p0 * (percent * .01);
var currentInhab = increaseInHab + p0 + aug;
for(var n = 0;currentInHab < p;n++) {
console.log(n)
n++
console.log(currentInhab + increaseInHab);
currentInhab + increaseInHab;
}
return n;
}
currentInhab + increaseInHab;adds two numbers and does nothing with the result. Hint, you need to store it back into the variable you want to update.augis expected to be position number, negative number or0? "i just don't know what type of loop i should write to keep increasing the numbers." Ifaugcan be a negative number, the numbers are not guaranteed to increase, yes?