File size: 1,725 Bytes
4600d8e | 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 | // Gerenciador de Abas
function openTab(tabName) {
// Esconder todas as seções
const contents = document.querySelectorAll('.tab-content');
contents.forEach(content => content.classList.remove('active'));
// Remover estado ativo dos links
const links = document.querySelectorAll('.tab-link');
links.forEach(link => link.classList.remove('active'));
// Ativar a seção e o link clicado
document.getElementById(tabName).classList.add('active');
document.getElementById('link-' + tabName).classList.add('active');
window.scrollTo({ top: 0, behavior: 'smooth' });
}
// Lógica da Calculadora de Juros Compostos
function calculateInterest() {
const initial = parseFloat(document.getElementById('initial').value) || 0;
const monthly = parseFloat(document.getElementById('monthly').value) || 0;
const rateAnnual = parseFloat(document.getElementById('rate').value) || 0;
const years = parseFloat(document.getElementById('years').value) || 0;
const months = years * 12;
const rateMonthly = (rateAnnual / 100) / 12;
// Fórmula: A = P(1+r)^n + PMT [ ((1+r)^n - 1) / r ]
let total = initial * Math.pow(1 + rateMonthly, months);
if (rateMonthly > 0) {
total += monthly * ((Math.pow(1 + rateMonthly, months) - 1) / rateMonthly);
} else {
total += monthly * months;
}
const formatter = new Intl.NumberFormat('pt-BR', { style: 'currency', currency: 'BRL' });
document.getElementById('result-value').innerText = formatter.format(total);
document.getElementById('result-details').innerText = `Projeção baseada em ${months} meses de aportes.`;
document.getElementById('calc-result').style.display = 'block';
}
|