Science Quiz Bowl Sheet Generator
Configure questions in the Data Configuration tab and click "Generate Quiz Sheet."
No questions added yet.
"; } // Sort by round and type for structured display var sortedQuestions = appState.questions.slice().sort(function(a, b) { if (a.round !== b.round) return a.round.localeCompare(b.round); if (a.type === "Toss-Up" && b.type === "Bonus") return -1; if (a.type === "Bonus" && b.type === "Toss-Up") return 1; return 0; }); sortedQuestions.forEach(function(q) { var item = document.createElement("div"); item.className = "qbg-question-item"; item.innerHTML = ` [R${q.round}] ${q.type} (${q.category}) - ${q.text.substring(0, 40)}... `; questionListDiv.appendChild(item); }); } function renderDashboardTab() { appState.quizTitle = quizTitleInput.value; appState.quizDate = quizDateInput.value; var rounds = {}; appState.questions.forEach(function(q) { var roundKey = q.round || 'Unassigned'; if (!rounds[roundKey]) { rounds[roundKey] = { 'Toss-Up': [], 'Bonus': [] }; } rounds[roundKey][q.type].push(q); }); var roundsHtml = ''; var sortedRoundKeys = Object.keys(rounds).sort(); var questionCounter = 0; sortedRoundKeys.forEach(function(roundKey) { var tossUps = rounds[roundKey]['Toss-Up']; var bonuses = rounds[roundKey]['Bonus']; if (tossUps.length + bonuses.length === 0) return; roundsHtml += `Round ${roundKey} Questions
Toss-Up Questions
${tossUps.map(function(q, index) {
questionCounter++;
return `
`;
}).join('')}
${questionCounter}. [${q.category}] ${q.text}
Difficulty: ${q.difficulty}
ANSWER: ${q.answer}
Bonus Questions
${bonuses.map(function(q) {
questionCounter++;
return `
`;
}).join('')}
${questionCounter}. [${q.category}] ${q.text}
Difficulty: ${q.difficulty}
ANSWER: ${q.answer}
${appState.quizTitle.toUpperCase()}
${appState.quizDate} | Total Questions: ${appState.questions.length}
`;
if (roundsHtml === '') {
quizContentDiv.innerHTML = 'Error: No questions have been added to the quiz sheet.
'; } else { quizContentDiv.innerHTML = metaHtml + roundsHtml; } } // --- Event Handlers --- // Update Dashboard Button updateBtn.addEventListener("click", function() { renderDashboardTab(); showTab(1); // Switch to Dashboard }); // Add Question addQBtn.addEventListener("click", function() { var type = qTypeSelect.value; var category = qCategorySelect.value; var difficulty = qDifficultySelect.value; var round = qRoundInput.value.trim(); var text = qTextInput.value.trim(); var answer = qAnswerInput.value.trim(); if (!text || !answer || !round) { alert("Please fill in the Question Text, Answer, and Round Number."); return; } var newQuestion = { id: Date.now(), type: type, category: category, difficulty: difficulty, round: round, text: text, answer: answer }; appState.questions.push(newQuestion); renderConfigTab(); // Clear form fields qTextInput.value = ""; qAnswerInput.value = ""; }); // Remove Question (Event Delegation) questionListDiv.addEventListener("click", function(e) { if (e.target.classList.contains("qbg-remove-btn")) { var id = parseInt(e.target.dataset.id); appState.questions = appState.questions.filter(function(q) { return q.id !== id; }); renderConfigTab(); } }); // PDF Download pdfBtn.addEventListener("click", function() { var jsPDF = window.jspdf.jsPDF; var titleSlug = quizTitleInput.value.replace(/[^a-zA-Z0-9\s]/g, '').replace(/\s/g, '_').substring(0, 30) || 'Quiz_Sheet'; var fileName = `${titleSlug}_Sheet.pdf`; html2canvas(exportArea, { scale: 2, useCORS: true, backgroundColor: '#ffffff' }).then(function(canvas) { var imgData = canvas.toDataURL('image/png'); var doc = new jsPDF({ orientation: 'p', unit: 'pt', format: 'letter' }); var pdfWidth = doc.internal.pageSize.getWidth(); var pdfHeight = doc.internal.pageSize.getHeight(); var imgProps = doc.getImageProperties(imgData); var imgWidth = imgProps.width; var imgHeight = imgProps.height; var margin = 40; var usableWidth = pdfWidth - (2 * margin); var ratio = usableWidth / imgWidth; var scaledHeight = imgHeight * ratio; // Handle multi-page if content exceeds page height if (scaledHeight > pdfHeight - (2 * margin)) { var pageHeight = pdfHeight - (2 * margin); var heightLeft = scaledHeight; var position = 0; while (heightLeft > 0) { doc.addImage(imgData, 'PNG', margin, position + margin, usableWidth, scaledHeight); heightLeft -= pageHeight; position -= pageHeight; if (heightLeft > 0) { doc.addPage(); } } } else { // Single page doc.addImage(imgData, 'PNG', margin, margin, usableWidth, scaledHeight); } doc.save(fileName); }).catch(function(err) { console.error("QBG PDF Error:", err); // alert("An error occurred while generating the PDF."); // Per spec }); }); // --- Initial Load --- renderConfigTab(); renderDashboardTab(); showTab(0); // Start on Config tab });