Reputation: 21
Problem: You have deposited a sum into your bank account for 3 years. The bank has announced an interest of 5% per year. Each time the interest is calculated and added to your deposit. You have to calculate the amount in your deposit for each year. Also I must print the number with two numbers after the decimal point.
let i = gets();
let input = Number(i);
let firstYear = input + (input*(5/100));
let secondYear = firstYear + (firstYear*(5/100));
let thirdYear = secondYear + (secondYear*(5/100));
let printFirst = firstYear.toFixed(2);
let printSecond = secondYear.toFixed(2);
let printThird = thirdYear.toFixed(2);
print(printFirst);
print(printSecond);
print(printThird);
Upvotes: 1
Views: 299
Reputation: 13
You can use a for loop like this
for(let i=0;i < 3;i++){
sum += sum * 0.05;
console.log(`${i} year: ${sum.toFixed(2)}`)
}
Upvotes: 1