Changed around line 1
+ document.addEventListener('DOMContentLoaded', () => {
+ const sliders = document.querySelectorAll('input[type="range"]');
+ const csScore = document.getElementById('cs-score');
+ const altScore = document.getElementById('alt-score');
+ const csFactors = document.getElementById('cs-factors');
+ const altFactors = document.getElementById('alt-factors');
+
+ function updateSliderValue(slider) {
+ const valueDisplay = slider.parentElement.querySelector('.value');
+ valueDisplay.textContent = `${slider.value}%`;
+ }
+
+ function calculateScores() {
+ const values = {
+ techInterest: parseInt(document.getElementById('tech-interest').value),
+ mathSkills: parseInt(document.getElementById('math-skills').value),
+ jobSecurity: parseInt(document.getElementById('job-security').value),
+ salaryImportance: parseInt(document.getElementById('salary-importance').value)
+ };
+
+ // Calculate CS Score
+ const csWeight = {
+ techInterest: 0.35,
+ mathSkills: 0.25,
+ jobSecurity: 0.20,
+ salaryImportance: 0.20
+ };
+
+ const csTotal = Object.keys(values).reduce((acc, key) => {
+ return acc + (values[key] * csWeight[key]);
+ }, 0);
+
+ // Calculate Alternative Careers Score
+ const altWeight = {
+ techInterest: 0.15,
+ mathSkills: 0.15,
+ jobSecurity: 0.35,
+ salaryImportance: 0.35
+ };
+
+ const altTotal = Object.keys(values).reduce((acc, key) => {
+ return acc + (values[key] * altWeight[key]);
+ }, 0);
+
+ // Update scores
+ csScore.textContent = `${Math.round(csTotal)}%`;
+ altScore.textContent = `${Math.round(altTotal)}%`;
+
+ // Update score circle backgrounds
+ document.querySelector('.cs-score .score-circle').style.setProperty('--percentage', `${csTotal}%`);
+ document.querySelector('.alt-score .score-circle').style.setProperty('--percentage', `${altTotal}%`);
+
+ // Update factors
+ updateFactors(values, csFactors, true);
+ updateFactors(values, altFactors, false);
+ }
+
+ function updateFactors(values, element, isCS) {
+ element.innerHTML = '';
+ const factors = [];
+
+ if (isCS) {
+ if (values.techInterest >= 70) factors.push('Strong tech interest is perfect for CS');
+ if (values.mathSkills >= 70) factors.push('Strong math skills are beneficial');
+ if (values.jobSecurity >= 70) factors.push('CS offers excellent job security');
+ if (values.salaryImportance >= 70) factors.push('CS typically offers high salaries');
+ } else {
+ if (values.techInterest < 50) factors.push('May prefer non-technical roles');
+ if (values.mathSkills < 50) factors.push('Other fields may require less math');
+ if (values.jobSecurity >= 70) factors.push('Many stable career alternatives exist');
+ if (values.salaryImportance >= 70) factors.push('Many high-paying alternatives available');
+ }
+
+ factors.forEach(factor => {
+ const li = document.createElement('li');
+ li.textContent = factor;
+ element.appendChild(li);
+ });
+ }
+
+ sliders.forEach(slider => {
+ slider.addEventListener('input', () => {
+ updateSliderValue(slider);
+ calculateScores();
+ });
+ });
+
+ // Initial calculation
+ calculateScores();
+ });