Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

118
Views
JavaScript calculating deposit in bank for 3 years

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);
about 4 years ago · Juan Pablo Isaza
2 answers
Answer question

0

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)}`)
}
about 4 years ago · Juan Pablo Isaza Report

0

I would write this as a comment, but I don't have enough reputation yet.

I think the main issue is that you (are getting/would get) an error when running your code. You haven't included the error in your question, which means you probably haven't actually tried running it yet.

Anyway, to fix it note that print(...) is not a javascript built-in. If you've only used python before it's probably not obvious, but the equivalent in javascript is console.log(...)


edit

Looking at your question again, you also have gets() on the first line, which is also not a javascript built-in. But it's not a python built-in either as far as I know. Regardless, if you are trying to get user input in JS, you would use prompt('enter a number: ')

about 4 years ago · Juan Pablo Isaza Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!