Created
July 23, 2021 14:11
-
-
Save ooredroxoo/433ab636bfbbeaa8f63d9b244436d831 to your computer and use it in GitHub Desktop.
Simulação Simples de Juros
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
let calculaJuros = () => { | |
let aporteMensal = 2500; // 2.5k reais | |
let jurosMensais = 0.005; // 0.5% | |
let meses = 12 * 20; // 20 anos | |
let acumulado = 0; | |
for(let i = 0; i < meses; i++) { | |
let juros = acumulado * jurosMensais; | |
acumulado += aporteMensal + juros; | |
if (i%6 == 0) { | |
console.log(`Mês ${i}: ${acumulado.toLocaleString('en-US', { | |
minimumIntegerDigits: 2, | |
useGrouping: false | |
})} - Juros ${juros.toLocaleString('en-US', { | |
minimumIntegerDigits: 2, | |
useGrouping: false | |
})} - Aporte: ${aporteMensal}`); | |
} | |
if (i%12 == 0) { | |
aporteMensal += 500; // Aumentando o aporte mensal em 500 reais a cada 12 meses. | |
} | |
} | |
console.log(`Total Acumulado: ${acumulado.toLocaleString('en-US', { | |
minimumIntegerDigits: 2, | |
useGrouping: false | |
})}`) | |
}; | |
calculaJuros(); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment