Changed around line 1
+ document.addEventListener('DOMContentLoaded', function() {
+ const calculateBtn = document.getElementById('calculate-btn');
+ const resultDetails = document.getElementById('result-details');
+ const riskPercentage = document.getElementById('risk-percentage');
+
+ calculateBtn.addEventListener('click', function() {
+ const savings = parseFloat(document.getElementById('savings').value) || 0;
+ const emergencyFund = parseFloat(document.getElementById('emergency-fund').value) || 0;
+ const expenses = parseFloat(document.getElementById('expenses').value) || 0;
+ const experience = parseFloat(document.getElementById('experience').value) || 0;
+ const clients = document.getElementById('clients').value;
+ const portfolio = document.getElementById('portfolio').value;
+
+ // Calculate risk score
+ let riskScore = calculateRiskScore(savings, emergencyFund, expenses, experience, clients, portfolio);
+ let riskLevel = getRiskLevel(riskScore);
+
+ // Update UI
+ riskPercentage.textContent = `${riskScore}%`;
+ displayResults(riskLevel, savings, emergencyFund, expenses);
+ });
+
+ function calculateRiskScore(savings, emergencyFund, expenses, experience, clients, portfolio) {
+ let score = 100;
+
+ // Financial factors
+ const monthsOfRunway = emergencyFund / expenses;
+ score -= monthsOfRunway * 5; // Deduct 5 points per month of runway
+ score -= (savings / expenses) * 2; // Deduct points based on savings ratio
+
+ // Experience factors
+ score -= experience * 3; // Deduct 3 points per year of experience
+
+ // Client base factors
+ switch(clients) {
+ case "1-2 clients": score -= 10; break;
+ case "3-5 clients": score -= 20; break;
+ case "5+ clients": score -= 30; break;
+ }
+
+ // Portfolio factors
+ switch(portfolio) {
+ case "Basic portfolio": score -= 10; break;
+ case "Strong portfolio": score -= 20; break;
+ case "Extensive portfolio": score -= 30; break;
+ }
+
+ return Math.max(0, Math.min(100, Math.round(score)));
+ }
+
+ function getRiskLevel(score) {
+ if (score < 20) return "Low Risk";
+ if (score < 40) return "Moderate-Low Risk";
+ if (score < 60) return "Moderate Risk";
+ if (score < 80) return "Moderate-High Risk";
+ return "High Risk";
+ }
+
+ function displayResults(riskLevel, savings, emergencyFund, expenses) {
+ const monthsOfRunway = Math.round((emergencyFund / expenses) * 10) / 10;
+
+ resultDetails.innerHTML = `
+
${riskLevel}
+
Financial Runway: ${monthsOfRunway} months
+
Monthly Expenses: $${expenses}
+
Current Savings: $${savings}
+
Recommendations:
+ ${getRecommendations(riskLevel, monthsOfRunway)}
+
+ `;
+ }
+
+ function getRecommendations(riskLevel, monthsOfRunway) {
+ let recommendations = [];
+
+ if (monthsOfRunway < 6) {
+ recommendations.push("Build emergency fund to cover at least 6 months of expenses");
+ }
+ if (riskLevel.includes("High")) {
+ recommendations.push("Consider part-time freelancing before full transition");
+ recommendations.push("Focus on securing long-term contracts before quitting");
+ }
+
+ return recommendations.map(rec => `
${rec}`).join('');+ }
+ });