Skip to content

Instantly share code, notes, and snippets.

@ooredroxoo
Created July 23, 2021 14:11
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save ooredroxoo/433ab636bfbbeaa8f63d9b244436d831 to your computer and use it in GitHub Desktop.
Save ooredroxoo/433ab636bfbbeaa8f63d9b244436d831 to your computer and use it in GitHub Desktop.
Simulação Simples de Juros
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