Test Vocacional CHASIDE
Test Vocacional CHASIDE
`;
}
// Emoji de ánimo aleatorio
const emojis = ['😊','🚀','✨','💪','🎯','🌟','👍'];
div.innerHTML += `
${emojis[Math.floor(Math.random()*emojis.length)]}
`;
preguntasDiv.appendChild(div);
}
}
renderPreguntas();
/* ---------- VALIDACIÓN ---------- */
const nombre = document.getElementById('nombre');
const correo = document.getElementById('correo');
const telefono = document.getElementById('telefono');
const institucion = document.getElementById('institucion');
function validarEmail(email){
return /^[^\s@]+@[^\s@]+\.[^\s@]+$/.test(email);
}
function validarTelefono(tel){
return /^\d{10}$/.test(tel);
}
function validarPaso0(){
let ok = true;
if(nombre.value.trim().length < 3){ document.getElementById('err-nombre').style.display='block'; ok=false; } else { document.getElementById('err-nombre').style.display='none'; }
if(!validarEmail(correo.value.trim())){ document.getElementById('err-correo').style.display='block'; ok=false; } else { document.getElementById('err-correo').style.display='none'; }
if(!validarTelefono(telefono.value.trim())){ document.getElementById('err-telefono').style.display='block'; ok=false; } else { document.getElementById('err-telefono').style.display='none'; }
if(institucion.value.trim().length < 3){ document.getElementById('err-institucion').style.display='block'; ok=false; } else { document.getElementById('err-institucion').style.display='none'; }
document.getElementById('btnNext').disabled = !ok;
return ok;
}
[nombre,correo,telefono,institucion].forEach(el=>el.addEventListener('input',validarPaso0));
/* ---------- PROGRESO ---------- */
function actualizarProgreso(){
const total = 49;
let respondidas = 0;
for(let i=0;i<49;i++){
if(form['q'+i] && form['q'+i].value !== '') respondidas++;
}
const porcentaje = Math.round((respondidas/total)*100);
document.getElementById('progressFill').style.width = porcentaje+'%';
document.getElementById('progressText').textContent = porcentaje+' % contestado';
}
form.addEventListener('change',actualizarProgreso);
/* ---------- NAVEGACIÓN ---------- */
function changeStep(dir){
if(currentStep === 0 && dir === 1 && !validarPaso0()) return;
const steps = document.querySelectorAll('.step');
steps[currentStep].classList.remove('active');
currentStep += dir;
if(currentStep < 0) currentStep = 0;
if(currentStep >= totalSteps) currentStep = totalSteps-1;
steps[currentStep].classList.add('active');
document.querySelector('.prev').style.display = currentStep===0?'none':'inline-block';
document.getElementById('btnNext').style.display = currentStep===totalSteps-1?'none':'inline-block';
document.getElementById('btnFinish').style.display = currentStep===totalSteps-1?'inline-block':'none';
}
/* ---------- RESULTADOS ---------- */
function finishTest(){
const puntos = {C:0,H:0,A:0,S:0,I:0,D:0,E:0};
const data = new FormData(form);
for(let i=0;i<49;i++){
const v = parseInt(data.get('q'+i))||0;
const area = Object.keys(areas)[Math.floor(i/7)];
puntos[area] += v;
}
const sorted = Object.entries(puntos).sort((a,b)=>b[1]-a[1]);
const topAreas = document.getElementById('topAreas');
topAreas.innerHTML = '';
sorted.forEach(([area,pts])=>{
topAreas.innerHTML += `
${areas[area].nombre}: ${pts} puntos`;
});
const top1 = sorted[0][0];
document.getElementById('carreras').innerHTML = `
Carreras sugeridas (${areas[top1].nombre}):
${areas[top1].carreras.join(', ')}.`;
document.querySelectorAll('.step').forEach(s=>s.classList.remove('active'));
document.getElementById('resultados').classList.add('active');
document.querySelector('.nav-buttons').style.display='none';
const nombreVal = nombre.value.trim();
const correoVal = correo.value.trim();
const telVal = telefono.value.trim();
const instVal = institucion.value.trim();
window.resultadosTexto = `Resultados Test Vocacional CHASIDE\n\n`+
`Nombre: ${nombreVal}\nCorreo: ${correoVal}\nTeléfono: ${telVal}\nInstitución: ${instVal}\n\n`+
sorted.map(([a,p])=>`${areas[a].nombre}: ${p} pts`).join('\n')+
`\n\nCarreras sugeridas (${areas[top1].nombre}): ${areas[top1].carreras.join(', ')}.`;
}
/* ---------- PDF ---------- */
document.getElementById('downloadPdf').onclick = function(){
const {jsPDF} = window.jspdf;
const doc = new jsPDF();
doc.setFontSize(12);
const lines = window.resultadosTexto.split('\n');
let y = 10;
lines.forEach(l=>{ doc.text(l,10,y); y+=7; });
doc.save('resultados-chaside.pdf');
};
/* ---------- EMAIL ---------- */
document.getElementById('sendEmail').onclick = function(){
const subject = encodeURIComponent("Resultados Test Vocacional CHASIDE");
const body = encodeURIComponent(window.resultadosTexto);
window.location.href = `mailto:?subject=${subject}&body=${body}`;
};