function depositProfit(deposit, rate, threshold) {
// use a while loop that exits when we exceed the threshold account balance
// Increment the year starting at 0 (initial deposit) and return when we exceed threshold
let endYearBalance = deposit
let currentYear = 0
while (endYearBalance < threshold) {
currentYear += 1
endYearBalance *= (rate + 100)/ 100
}
return currentYear
}
/**
* Test Suite
*/
describe('depositProfit()', () => {
it('returns number of years it will take to hit threshold based off of deposit & rate', () => {
// arrange
const deposit = 100;
const rate = 20;
const threshold = 170;
// act
const result = depositProfit(deposit, rate, threshold)
// log
console.log("result: ", result);
// assert
expect(result).toBe(3);
});
});