function depositProfit(deposit, rate, threshold) {
// write code here.
let year = 0;
let balance = deposit;
const rateDecimal = rate / 100;
console.log(rateDecimal);
// for(let i = 1; i < 4; i++){
// year ++;
// console.log(year);
// balance = (balance * rateDecimal) + balance;
// console.log(balance);
// }
// console.log(`Ending Balance: ${balance}`);
// answer = balance.ToFixed();
// console.log(answer);
// return answer;
while (balance < threshold) {
balance = (balance * rateDecimal) + balance;
console.log(balance);
year++;
}
console.log(year);
return year;
}
/**
* 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);
});
});