AI-Based Personal Finance Health Score Calculator

AI-Based Personal Finance Health Score Calculator

Get your financial score and personalized AI-powered recommendations.

Step 1: Your Income & Savings

Step 2: Your Expenses & Debt

Step 3: Your Assets

Calculating your score and getting AI analysis...

`; } function displayResults() { const category = getScoreCategory(state.score); const resultsHTML = `

Your Financial Health Score

Savings Rate: ${state.savingsRate.toFixed(1)}%
Debt-to-Income Ratio: ${state.debtToIncomeRatio.toFixed(1)}%
Emergency Fund: ${state.emergencyFundMonths.toFixed(1)} months
${renderMarkdown(state.aiRecommendations)}

This tool provides a simplified, illustrative analysis for educational purposes and is not financial advice. Consult with a qualified professional for personalized guidance.

`; resultsContentEl.innerHTML = resultsHTML; pdfDownloadAreaEl.classList.remove('hidden'); // Render the chart const ctx = document.getElementById('scoreChart').getContext('2d'); if (chartInstance) chartInstance.destroy(); chartInstance = new Chart(ctx, { type: 'doughnut', data: { datasets: [{ data: [state.score, 100 - state.score], backgroundColor: [category.color.replace('text-', '').replace('-500', ''), '#e5e7eb'], borderColor: ['#fff'], borderWidth: 4, circumference: 270, rotation: 225, }] }, options: { responsive: true, cutout: '75%', plugins: { tooltip: { enabled: false }, legend: { display: false } } } }); // Add score text inside the doughnut const scoreText = document.createElement('div'); scoreText.className = `absolute inset-0 flex flex-col items-center justify-center pointer-events-none`; scoreText.innerHTML = `${state.score}${category.text}`; ctx.canvas.parentNode.appendChild(scoreText); } function renderMarkdown(text) { // Simple markdown to HTML conversion return text .replace(/^### (.*$)/gim, '

$1

') .replace(/\n\s*-\s/g, '
  • ') .replace(/<\/li>/, '') // remove first junk tag .replace(/$/, '
  • ') // close last tag .replace(/
  • /g, '
  • ') .replace(/\*\*(.*)\*\*/g, '$1') .replace(/\n/g, '
    '); } function createPdf() { const pdfArea = document.getElementById('pdf-export-area'); if (!pdfArea) { return; } const originalButtonText = downloadPdfButton.textContent; downloadPdfButton.textContent = 'Generating...'; downloadPdfButton.disabled = true; html2canvas(pdfArea, { scale: 2, useCORS: true, logging: false }).then(canvas => { const imgData = canvas.toDataURL('image/png'); const { jsPDF } = window.jspdf; const pdf = new jsPDF({ orientation: 'portrait', unit: 'mm', format: 'a4' }); const pdfWidth = pdf.internal.pageSize.getWidth(); const pdfHeight = pdf.internal.pageSize.getHeight(); const imgWidth = pdfWidth - 20; const imgHeight = (canvas.height * imgWidth) / canvas.width; let heightLeft = imgHeight; let position = 15; pdf.setFont('helvetica', 'bold'); pdf.setFontSize(18); pdf.text('Personal Finance Health Report', pdfWidth / 2, 10, { align: 'center' }); pdf.addImage(imgData, 'PNG', 10, position, imgWidth, imgHeight); heightLeft -= (pdfHeight - position - 15); while (heightLeft > 0) { position = heightLeft - imgHeight; pdf.addPage(); pdf.addImage(imgData, 'PNG', 10, position, imgWidth, imgHeight); heightLeft -= pdfHeight; } pdf.save('Finance_Health_Report.pdf'); }).catch(err => { console.error("PDF generation error:", err); alert("An error occurred while creating the PDF."); }).finally(() => { downloadPdfButton.textContent = originalButtonText; downloadPdfButton.disabled = false; }); } // --- Initial Setup --- updateUI(); });
  • Scroll to Top