Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

119
Visualizações
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 Respostas
Responde à pergunta

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 Relatório

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 Relatório
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda