// PVA Archetype Quiz - Complete JavaScript Rewrite
(function() {
'use strict';
// Quiz state variables
let currentQuestion = 1;
const totalQuestions = 5;
let scores = {
guardian: 0,
pioneer: 0,
strategist: 0,
visionary: 0
};
// Archetype definitions
const archetypes = {
guardian: {
title: "The Guardian",
description: "You are the foundation of any society. Your strength lies in your practicality, loyalty, and desire to protect and provide for others. You create the stability that allows others to dream and explore. You are dependable, nurturing, and the heart of your community.",
traits: [
"Deeply loyal and reliable",
"Practical problem-solver",
"Natural protector and nurturer",
"Values tradition and stability",
"Excellent at creating systems that work"
]
},
pioneer: {
title: "The Pioneer",
description: "You are the adventurous spirit who pushes boundaries and explores new frontiers. Your courage and adaptability inspire others to break free from limitations. You thrive on freedom, authenticity, and hands-on experience. You bring vitality and fresh perspectives to any situation.",
traits: [
"Highly adaptable and resourceful",
"Authentic and spontaneous",
"Natural risk-taker and explorer",
"Values freedom and independence",
"Excellent at thinking on your feet"
]
},
strategist: {
title: "The Strategist",
description: "You are a seeker of truth and a master of systems. Your mind is wired to analyze, understand, and optimize. You find deep satisfaction in uncovering how things work and improving them. You are the innovator, the architect of progress, and the keeper of logic.",
traits: [
"Analytical and logical thinker",
"Natural problem-solver and innovator",
"Excellent at seeing patterns and systems",
"Values competence and knowledge",
"Thrives on complex challenges"
]
},
visionary: {
title: "The Visionary",
description: "You are an inspiring force who sees potential in people and situations others might miss. Your empathy and charisma allow you to unite people around shared ideals. You create meaning, foster connection, and guide others toward a better future through your values and vision.",
traits: [
"Highly empathetic and charismatic",
"Natural leader and inspirator",
"Excellent at seeing potential in people",
"Values meaning and human connection",
"Thrives on collaborative creativity"
]
}
};
// Utility functions
function getElement(id) {
return document.getElementById(id);
}
function hideElement(element) {
if (element) element.style.display = 'none';
}
function showElement(element) {
if (element) element.style.display = 'block';
}
function updateProgress() {
const progressBar = getElement('progressBar');
if (progressBar) {
const progress = ((currentQuestion - 1) / totalQuestions) * 100;
progressBar.style.width = progress + '%';
}
}
function clearSelections(container) {
if (container) {
const options = container.querySelectorAll('.option');
options.forEach(option => option.classList.remove('selected'));
}
}
function enableNextButton() {
const nextBtn = getElement('nextBtn');
if (nextBtn) {
nextBtn.disabled = false;
}
}
function disableNextButton() {
const nextBtn = getElement('nextBtn');
if (nextBtn) {
nextBtn.disabled = true;
}
}
// Main quiz functions
window.startQuiz = function() {
const intro = getElement('intro');
const quiz = getElement('quiz');
hideElement(intro);
showElement(quiz);
updateProgress();
};
window.selectOption = function(element, archetype) {
if (!element || !archetype) return;
// Find the parent question container
const questionContainer = element.closest('.question-container');
// Clear previous selections in this question
clearSelections(questionContainer);
// Select current option
element.classList.add('selected');
// Update score
if (scores.hasOwnProperty(archetype)) {
scores[archetype]++;
}
// Enable next button
enableNextButton();
};
window.nextQuestion = function() {
if (currentQuestion < totalQuestions) {
// Hide current question
const currentQ = getElement(`question${currentQuestion}`);
if (currentQ) {
currentQ.classList.remove('active');
hideElement(currentQ);
}
// Move to next question
currentQuestion++;
// Show next question
const nextQ = getElement(`question${currentQuestion}`);
if (nextQ) {
nextQ.classList.add('active');
showElement(nextQ);
}
// Update progress
updateProgress();
// Disable next button until selection
disableNextButton();
// Update button text for last question
if (currentQuestion === totalQuestions) {
const nextBtn = getElement('nextBtn');
if (nextBtn) {
nextBtn.textContent = 'Discover My Archetype';
nextBtn.onclick = showResult;
}
}
}
};
window.showResult = function() {
// Calculate the winning archetype
let maxScore = 0;
let resultArchetype = 'guardian';
for (let archetype in scores) {
if (scores[archetype] > maxScore) {
maxScore = scores[archetype];
resultArchetype = archetype;
}
}
// Get the result data
const result = archetypes[resultArchetype];
// Update result elements
const titleEl = getElement('archetypeTitle');
const descEl = getElement('archetypeDescription');
const traitList = getElement('traitList');
if (titleEl) titleEl.textContent = result.title;
if (descEl) descEl.textContent = result.description;
if (traitList) {
traitList.innerHTML = '';
result.traits.forEach(trait => {
const li = document.createElement('li');
li.textContent = trait;
traitList.appendChild(li);
});
}
// Hide quiz, show result
const quiz = getElement('quiz');
const resultContainer = getElement('result');
hideElement(quiz);
showElement(resultContainer);
};
window.resetQuiz = function() {
// Reset state
currentQuestion = 1;
scores = { guardian: 0, pioneer: 0, strategist: 0, visionary: 0 };
// Reset UI elements
const intro = getElement('intro');
const quiz = getElement('quiz');
const result = getElement('result');
const nextBtn = getElement('nextBtn');
// Show intro, hide others
showElement(intro);
hideElement(quiz);
hideElement(result);
// Reset next button
if (nextBtn) {
nextBtn.textContent = 'Next Question';
nextBtn.onclick = nextQuestion;
nextBtn.disabled = true;
}
// Clear all selections
const allOptions = document.querySelectorAll('#pva-archetype-quiz .option');
allOptions.forEach(option => option.classList.remove('selected'));
// Reset question containers
const allQuestions = document.querySelectorAll('#pva-archetype-quiz .question-container');
allQuestions.forEach((container, index) => {
container.classList.remove('active');
hideElement(container);
if (index === 0) {
container.classList.add('active');
showElement(container);
}
});
// Reset progress
updateProgress();
};
// Initialize the quiz when DOM is ready
function initializeQuiz() {
// Ensure all question containers except the first are hidden
const allQuestions = document.querySelectorAll('#pva-archetype-quiz .question-container');
allQuestions.forEach((container, index) => {
if (index === 0) {
container.classList.add('active');
showElement(container);
} else {
container.classList.remove('active');
hideElement(container);
}
});
// Initialize progress bar
updateProgress();
// Ensure next button starts disabled
disableNextButton();
console.log('PVA Archetype Quiz initialized successfully');
}
// Initialize when DOM is ready
if (document.readyState === 'loading') {
document.addEventListener('DOMContentLoaded', initializeQuiz);
} else {
initializeQuiz();
}
})();