Your Style Breakdown
This chart shows your score for each of the four primary learning styles. While you have a dominant style, you likely use a mix of all four.
Tailored Study Strategies
`;
// Render chart for PDF (must be done while element is technically in DOM)
const pdfCtx = document.getElementById('pdfChart').getContext('2d');
new Chart(pdfCtx, {
type: 'bar',
data: {
labels: ['Visual', 'Auditory', 'Reading/Writing', 'Kinesthetic'],
datasets: [{
label: 'Score',
data: [scores.V, scores.A, scores.R, scores.K],
backgroundColor: ['#60a5fa', '#a78bfa', '#f87171', '#fbbf24']
}]
},
options: {
indexAxis: 'y',
elements: { bar: { borderWidth: 2, } },
responsive: true,
plugins: { legend: { display: false } },
scales: { x: { beginAtZero: true, max: questions.length } }
}
});
}
async function generatePdf() {
const downloadBtn = document.getElementById('download-pdf-btn');
if (!downloadBtn) return;
downloadBtn.innerText = 'Generating PDF...';
downloadBtn.disabled = true;
const element = document.getElementById('pdf-template');
element.classList.remove('invisible', 'absolute', '-left-full');
element.style.position = 'absolute';
element.style.left = '0'; // Render in viewport for better canvas capture
element.style.top = '0';
element.style.zIndex = '-1'; // Hide behind other content
try {
// Wait for chart animations to complete
await new Promise(resolve => setTimeout(resolve, 500));
const { jsPDF } = window.jspdf;
const canvas = await html2canvas(element.querySelector('.assessment-report'), {
scale: 3,
backgroundColor: '#ffffff'
});
const imgData = canvas.toDataURL('image/png');
const pdf = new jsPDF({ orientation: 'p', unit: 'pt', format: 'a4' });
const pdfWidth = pdf.internal.pageSize.getWidth();
const pdfHeight = (canvas.height * pdfWidth) / canvas.width;
pdf.addImage(imgData, 'PNG', 0, 0, pdfWidth, pdfHeight);
pdf.save('My-Learning-Style-Report.pdf');
} catch(err) {
console.error("PDF generation failed:", err);
alert("Sorry, an error occurred while creating the PDF.");
} finally {
element.classList.add('invisible', 'absolute', '-left-full');
element.style.position = '';
element.style.left = '';
element.style.top = '';
element.style.zIndex = '';
downloadBtn.innerText = 'Download Full Report';
downloadBtn.disabled = false;
}
}
// --- Initial State ---
startQuiz();
});