Changed around line 1
+ document.addEventListener('DOMContentLoaded', function() {
+ const calculateBtn = document.getElementById('calculate-btn');
+ const resultElement = document.getElementById('risk-result');
+ const explanationElement = document.getElementById('risk-explanation');
+
+ calculateBtn.addEventListener('click', function() {
+ const currentIncome = parseFloat(document.getElementById('current-income').value);
+ const freelanceIncome = parseFloat(document.getElementById('freelance-income').value);
+ const savingsBuffer = parseFloat(document.getElementById('savings-buffer').value);
+ const industryStability = document.getElementById('industry-stability').value;
+
+ if (!currentIncome || !freelanceIncome || !savingsBuffer) {
+ alert('Please fill in all fields');
+ return;
+ }
+
+ const incomeRatio = freelanceIncome / currentIncome;
+ const riskScore = calculateRiskScore(incomeRatio, savingsBuffer, industryStability);
+
+ displayResult(riskScore);
+ });
+
+ function calculateRiskScore(incomeRatio, savingsBuffer, industryStability) {
+ let score = 0;
+
+ // Income ratio factor
+ if (incomeRatio >= 1.5) score += 20;
+ else if (incomeRatio >= 1.2) score += 30;
+ else if (incomeRatio >= 1) score += 50;
+ else if (incomeRatio >= 0.8) score += 70;
+ else score += 90;
+
+ // Savings buffer factor
+ if (savingsBuffer >= 12) score -= 20;
+ else if (savingsBuffer >= 6) score -= 10;
+ else if (savingsBuffer >= 3) score += 10;
+ else score += 30;
+
+ // Industry stability factor
+ if (industryStability === 'High') score -= 20;
+ else if (industryStability === 'Medium') score += 10;
+ else score += 30;
+
+ // Normalize score between 0 and 100
+ score = Math.max(0, Math.min(100, score));
+
+ return score;
+ }
+
+ function displayResult(score) {
+ let riskLevel, explanation;
+
+ if (score <= 30) {
+ riskLevel = 'Low Risk';
+ explanation = 'Your financial situation and market conditions suggest a low-risk transition to freelancing.';
+ } else if (score <= 60) {
+ riskLevel = 'Moderate Risk';
+ explanation = 'You might face some challenges, but with proper planning, freelancing could work well for you.';
+ } else {
+ riskLevel = 'High Risk';
+ explanation = 'The transition to freelancing might be risky at this time. Consider building more savings or improving your market position first.';
+ }
+
+ resultElement.textContent = riskLevel;
+ explanationElement.textContent = explanation;
+ }
+ });