Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

123
Vistas
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 Respuestas
Responde la pregunta

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 Denunciar

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 Denunciar
Responde la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda