I'm supposed to create a function that will continue to double the first argument until it is greater than or equal to the 2nd argument. Every time it doubles, I add 20 to a counter.
However, for whatever reason, it doesn't seem to be adding 20 to the counter as it always returns 0 and does not print the console.log I included for each loop, which makes me think it's not running the loop.
Why isn't it running the loop and what am I doing wrong?
function bacteriaTime(currentNum, targetNum) {
let counter = 0
for (let i = currentNum; i >= targetNum; i *= 2) {
counter += 20;
console.log('bacteria count is ' + i + ' and ' + counter + ' have passed.')
}
return counter;
console.log(counter);
}
return counterwill be ignored because... you've returned.currentNumstarts as less thantargetNumcorrect? The condition is backwards then. You want to check for it being less thantargetNum.currentNumandtargetNum?currentNumas 0,targetNumas, say, 3.