Online Geology Rock Identification Quiz

Rock Identification Quiz

Test Your Geology Knowledge!

This quiz contains 10 questions to help you identify common types of rocks. Click the button below to begin.

Your answer: ${ua.selected} ${!ua.isCorrect ? ` | Correct answer: ${ua.correct}` : ''}

`; summaryList.appendChild(item); }); } async function downloadPDF() { if (typeof window.jspdf === 'undefined' || typeof window.html2canvas === 'undefined') { alert("PDF generation library not loaded. Please check connection."); return; } pdfLoader.classList.remove('hidden'); pdfDownloadBtn.disabled = true; restartBtn.disabled = true; try { const { jsPDF } = window.jspdf; const pdf = new jsPDF({ orientation: 'p', unit: 'mm', format: 'a4' }); const elementToCapture = document.getElementById('results-summary'); pdf.setFontSize(22); pdf.setFont('helvetica', 'bold'); pdf.text('Rock Identification Quiz Results', 105, 20, { align: 'center' }); pdf.setFontSize(16); pdf.setFont('helvetica', 'normal'); pdf.text(`Final Score: ${score} / ${questions.length}`, 105, 30, { align: 'center' }); const canvas = await html2canvas(elementToCapture, { scale: 2 }); const imgData = canvas.toDataURL('image/png'); const imgProps = pdf.getImageProperties(imgData); const pdfWidth = pdf.internal.pageSize.getWidth() - 20; // with margin const pdfHeight = (imgProps.height * pdfWidth) / imgProps.width; pdf.addImage(imgData, 'PNG', 10, 40, pdfWidth, pdfHeight); pdf.save('rock-quiz-results.pdf'); } catch (error) { console.error("PDF Generation Error:", error); alert("Sorry, an error occurred while generating the PDF."); } finally { pdfLoader.classList.add('hidden'); pdfDownloadBtn.disabled = false; restartBtn.disabled = false; } } // --- EVENT LISTENERS --- startBtn.addEventListener('click', startQuiz); nextBtn.addEventListener('click', showNextQuestion); restartBtn.addEventListener('click', startQuiz); pdfDownloadBtn.addEventListener('click', downloadPDF); });
Scroll to Top