function calculateScores() {
const pName = document.getElementById(‘pName’).value || “Unnamed Hero”;
const pAge = document.getElementById(‘pAge’).value;
// Helper function to average the 5 questions per category
const getAvg = (ids) => {
let sum = ids.reduce((acc, id) => acc + parseInt(document.getElementById(id).value), 0);
return Math.round(sum / 5);
};
const stats = {
STR: getAvg([‘str_q1’, ‘str_q2’, ‘str_q3’, ‘str_q4’, ‘str_q5’]),
INT: getAvg([‘int_q1’, ‘int_q2’, ‘int_q3’, ‘int_q4’, ‘int_q5’]),
CHA: getAvg([‘cha_q1’, ‘cha_q2’, ‘cha_q3’, ‘cha_q4’, ‘cha_q5’]),
SPI: getAvg([‘spi_q1’, ‘spi_q2’, ‘spi_q3’, ‘spi_q4’, ‘spi_q5’]),
GRT: getAvg([‘grt_q1’, ‘grt_q2’, ‘grt_q3’, ‘grt_q4’, ‘grt_q5’])
};
// Determine Class Based on Highest Stat
const highestStat = Object.keys(stats).reduce((a, b) => stats[a] > stats[b] ? a : b);
const classes = {
STR: “The Juggernaut”,
INT: “The Architect”,
CHA: “The Envoy”,
SPI: “The Mystic”,
GRT: “The Ironclad”
};
const initialClass = stats[highestStat] < 3 ? "The Awakened" : classes[highestStat];
// SAVE DATA: This allows other parts of your site (like the Quest Log) to see these stats
localStorage.setItem('playerStats', JSON.stringify({
name: pName,
age: pAge,
class: initialClass,
levels: stats,
lastUpdated: new Date().toLocaleDateString()
}));
displayResults(pName, pAge, initialClass, stats);
}
function displayResults(name, age, className, stats) {
const summaryHtml = `
${name} LVL ${age}
${className}
Attribute Matrix
‘; for (const [stat, lvl] of Object.entries(stats)) { const percent = lvl * 10; // Convert 1-10 to 10%-100% breakdownHtml += `
${stat}
LVL ${lvl}
`;
}
document.getElementById(‘player-summary’).innerHTML = summaryHtml;
document.getElementById(‘attribute-breakdown’).innerHTML = breakdownHtml;
}
