Changed around line 1
+ document.addEventListener('DOMContentLoaded', () => {
+ const questions = document.querySelectorAll('.question');
+ const progressBar = document.querySelector('.progress');
+ const resultDiv = document.querySelector('.result');
+ const resultContent = document.querySelector('.result-content');
+ const restartBtn = document.querySelector('.restart-btn');
+
+ let currentQuestion = 0;
+ let scores = [];
+
+ function updateProgress() {
+ const progress = ((currentQuestion) / questions.length) * 100;
+ progressBar.style.width = `${progress}%`;
+ }
+
+ function showResult() {
+ const weightedSum = scores.reduce((acc, score, index) => {
+ const weight = parseInt(questions[index].dataset.weight);
+ return acc + (score * weight);
+ }, 0);
+
+ const totalWeight = Array.from(questions).reduce((acc, q) =>
+ acc + parseInt(q.dataset.weight), 0);
+
+ const finalScore = (weightedSum / (totalWeight * 5)) * 100;
+
+ let recommendation;
+ if (finalScore >= 80) {
+ recommendation = "Based on your responses, you seem to be in a good position to continue your PhD. The challenges you're facing appear manageable.";
+ } else if (finalScore >= 60) {
+ recommendation = "You have some significant concerns, but they might be addressable. Consider discussing these with your advisor or department.";
+ } else {
+ recommendation = "You're facing several serious challenges. While the decision is yours, you might want to carefully evaluate if continuing serves your best interests.";
+ }
+
+ questions.forEach(q => q.style.display = 'none');
+ resultDiv.classList.remove('hidden');
+ resultContent.innerHTML = `
+
Score: ${Math.round(finalScore)}%
+ `;
+ }
+
+ document.addEventListener('click', (e) => {
+ if (!e.target.matches('button[data-value]')) return;
+
+ const value = parseInt(e.target.dataset.value);
+ scores.push(value);
+
+ if (currentQuestion < questions.length - 1) {
+ questions[currentQuestion].classList.remove('current');
+ currentQuestion++;
+ questions[currentQuestion].classList.add('current');
+ updateProgress();
+ } else {
+ showResult();
+ }
+ });
+
+ restartBtn.addEventListener('click', () => {
+ currentQuestion = 0;
+ scores = [];
+ resultDiv.classList.add('hidden');
+ questions.forEach((q, i) => {
+ q.style.display = i === 0 ? 'block' : 'none';
+ if (i === 0) q.classList.add('current');
+ });
+ updateProgress();
+ });
+
+ updateProgress();
+ });