Changed around line 1
+ const questions = [
+ {
+ question: "You find a mysterious map. Do you...",
+ answers: [
+ { text: "Follow it immediately", result: "adventurer" },
+ { text: "Study it carefully first", result: "scholar" }
+ ]
+ },
+ {
+ question: "A dragon appears! Do you...",
+ answers: [
+ { text: "Fight it bravely", result: "warrior" },
+ { text: "Try to reason with it", result: "diplomat" }
+ ]
+ },
+ {
+ question: "You reach a fork in the road. Do you...",
+ answers: [
+ { text: "Take the left path", result: "explorer" },
+ { text: "Take the right path", result: "strategist" }
+ ]
+ }
+ ];
+
+ const resultDescriptions = {
+ adventurer: "You're a true adventurer! Always ready for the next challenge.",
+ scholar: "Your wisdom and knowledge will guide you to great discoveries.",
+ warrior: "Your courage and strength will lead you to victory.",
+ diplomat: "Your charm and wit will help you navigate any situation.",
+ explorer: "Your curiosity and daring will take you to amazing places.",
+ strategist: "Your careful planning will ensure your success."
+ };
+
+ const questionElement = document.getElementById('question');
+ const answerButtonsElement = document.getElementById('answer-buttons');
+ const resultContainer = document.getElementById('result-container');
+ const resultTitle = document.getElementById('result-title');
+ const resultText = document.getElementById('result-text');
+ const restartButton = document.getElementById('restart-btn');
+
+ let currentQuestionIndex = 0;
+ let userResults = [];
+
+ function startQuiz() {
+ currentQuestionIndex = 0;
+ userResults = [];
+ resultContainer.classList.add('hidden');
+ showQuestion();
+ }
+
+ function showQuestion() {
+ const question = questions[currentQuestionIndex];
+ questionElement.innerText = question.question;
+ answerButtonsElement.innerHTML = '';
+ question.answers.forEach(answer => {
+ const button = document.createElement('button');
+ button.innerText = answer.text;
+ button.classList.add('btn');
+ button.addEventListener('click', () => selectAnswer(answer.result));
+ answerButtonsElement.appendChild(button);
+ });
+ }
+
+ function selectAnswer(result) {
+ userResults.push(result);
+ if (currentQuestionIndex < questions.length - 1) {
+ currentQuestionIndex++;
+ showQuestion();
+ } else {
+ showResult();
+ }
+ }
+
+ function showResult() {
+ const finalResult = determineFinalResult();
+ resultTitle.innerText = "Your Adventure Awaits!";
+ resultText.innerText = resultDescriptions[finalResult];
+ resultContainer.classList.remove('hidden');
+ }
+
+ function determineFinalResult() {
+ const resultCounts = {};
+ userResults.forEach(result => {
+ resultCounts[result] = (resultCounts[result] || 0) + 1;
+ });
+ return Object.keys(resultCounts).reduce((a, b) => resultCounts[a] > resultCounts[b] ? a : b);
+ }
+
+ restartButton.addEventListener('click', startQuiz);
+
+ startQuiz();