Reading Comprehension Exercises
Paste a text passage to generate a comprehension quiz.
Enter Your Text Passage
Quiz Results
Your results will be displayed here after you complete the quiz.
Your answer: ${String.fromCharCode(65 + userAnswers[index])}. ${q.options[userAnswers[index]]} ${isCorrect ? ' (Correct)' : ' (Incorrect)'}
${!isCorrect ? `Correct answer: ${String.fromCharCode(65 + q.correctAnswerIndex)}. ${q.options[q.correctAnswerIndex]}
` : ''}Explanation: ${q.explanation}
`; resultsContainer.appendChild(resultBlock); }); const scoreBlock = document.createElement('div'); scoreBlock.className = 'p-4 rounded-lg bg-blue-100 text-blue-800 text-center text-xl font-bold'; scoreBlock.textContent = `Your Final Score: ${score} out of ${quizData.length}`; resultsContainer.prepend(scoreBlock); pdfDownloadBtn.classList.remove('hidden'); }; /** * Generates and downloads a PDF of the results. */ const downloadResultsAsPDF = async () => { const { jsPDF } = window.jspdf; const pdfOutput = document.getElementById('pdf-output'); const canvas = await html2canvas(pdfOutput, { scale: 2, backgroundColor: '#ffffff' }); const imgData = canvas.toDataURL('image/png'); const pdf = new jsPDF({ orientation: 'portrait', unit: 'pt', format: 'a4' }); const pdfWidth = pdf.internal.pageSize.getWidth(); const imgProps = pdf.getImageProperties(imgData); const pdfHeight = (imgProps.height * pdfWidth) / imgProps.width; pdf.addImage(imgData, 'PNG', 40, 40, pdfWidth - 80, pdfHeight - 80); pdf.save('Reading-Comprehension-Results.pdf'); }; // --- Event Listeners --- generateQuizBtn.addEventListener('click', handleQuizGeneration); pdfDownloadBtn.addEventListener('click', downloadResultsAsPDF); // Initialize view showTab('quizTab'); });