Un personnage de mes romans vous ressemble-t-il ?

document.addEventListener(« DOMContentLoaded », function(){/* ========================= 1. ARCHÉTYPES AUTOMATIQUES ========================= */const profils = { combat: [], protect: [], intellect: [], rebel: [] };/* ⚠️ IMPORTANT : On utilise TON vrai objet personnages (déjà existant sur ton site) */Object.keys(personnages).forEach(code => {if(code.startsWith(« HB »)) profils.combat.push(code); else if(code.startsWith(« HC »)) profils.intellect.push(code); else if(code.startsWith(« FA ») || code.startsWith(« FB »)) profils.protect.push(code); else profils.rebel.push(code);});/* ========================= 2. QUESTIONS ========================= */const questions = [ { q: »Une menace surgit dans ton monde… », choices:[ {text: »Je combats sans hésiter », type: »combat »}, {text: »Je protège les autres », type: »protect »}, {text: »J’analyse la situation », type: »intellect »}, {text: »Je fais à ma manière », type: »rebel »} ] }, { q: »Ton instinct principal ? », choices:[ {text: »Force », type: »combat »}, {text: »Empathie », type: »protect »}, {text: »Logique », type: »intellect »}, {text: »Liberté », type: »rebel »} ] }, { q: »Dans un monde en ruine… », choices:[ {text: »Je dirige », type: »combat »}, {text: »Je soigne », type: »protect »}, {text: »Je cherche des réponses », type: »intellect »}, {text: »Je m’adapte », type: »rebel »} ] } ];/* ========================= 3. VARIABLES ========================= */let currentQ = 0; let score = {combat:0, protect:0, intellect:0, rebel:0};/* ========================= 4. START ========================= */document.getElementById(« startQuizBtn »).onclick = startQuiz;function startQuiz(){ currentQ = 0; score = {combat:0, protect:0, intellect:0, rebel:0}; showQuestion(); }/* ========================= 5. QUESTIONS ========================= */function showQuestion(){const box = document.getElementById(« quizBox »); const q = questions[currentQ];box.innerHTML = « 

> « +q.q+ »

« ;q.choices.forEach(choice => {const btn = document.createElement(« div »); btn.className = « quizChoice »; btn.textContent = choice.text;btn.onclick = () => { score[choice.type]++; currentQ++;if(currentQ < questions.length){ showQuestion(); } else { showResult(); } };box.appendChild(btn); }); }/* ========================= 6. RÉSULTAT INTELLIGENT ========================= */function showResult(){let dominant = Object.keys(score).reduce((a,b)=> score[a]>score[b]?a:b);let pool = profils[dominant];// sécurité si vide if(!pool || pool.length === 0){ pool = Object.keys(personnages); }let codeFinal = pool[Math.floor(Math.random()*pool.length)];let p = personnages[codeFinal];const box = document.getElementById(« quizBox »);box.innerHTML = `

>> PROFIL IDENTIFIÉ

${p.nom}

${p.phrase}

🎁 Code promo : ${p.promo}

`; }});
Retour en haut