Science Word Puzzle Generator

Science Word Puzzle Generator

1. Puzzle Metadata

2. Add Terms and Clues

Current Terms

Configure terms in the Data Configuration tab and click "Generate Puzzle Sheet."

No terms added yet.

"; } appState.terms.forEach(function(term) { var item = document.createElement("div"); item.className = "swp-term-item"; item.innerHTML = ` ${term.word} (${term.clue.substring(0, 40)}...) `; termListDiv.appendChild(item); }); } function renderDashboardTab() { appState.title = titleInput.value || "Untitled Puzzle"; appState.type = typeSelect.value; if (appState.terms.length === 0) { puzzleContentDiv.innerHTML = '

Error: Please add at least one term and clue.

'; return; } var cluesHtml = ''; var keyHtml = ''; // Sort terms alphabetically for clean list/crossword order var sortedTerms = appState.terms.slice().sort(function(a, b) { return a.word.localeCompare(b.word); }); if (appState.type === "Crossword") { // Clue List cluesHtml = sortedTerms.map(function(term, index) { return `
  • ${index + 1}. ${term.clue}
  • `; }).join(''); // Answer Key keyHtml = sortedTerms.map(function(term, index) { return `
  • ${index + 1}. ${term.word}
  • `; }).join(''); } else { // Word Search // Word List (Clues are optional/secondary) cluesHtml = sortedTerms.map(function(term, index) { return `
  • ${term.word} (${term.clue})
  • `; }).join(''); // Answer Key (just the words) keyHtml = sortedTerms.map(function(term) { return `
  • ${term.word}
  • `; }).join(''); } var content = `
    ${appState.title.toUpperCase()}
    ${appState.type} Clue/Key Sheet
    1. Clues / Word List
      ${cluesHtml}

    Note: A blank puzzle grid is not generated. Use this list to create your puzzle.

    2. Answer Key
      ${keyHtml}
    `; puzzleContentDiv.innerHTML = content; } // --- Event Handlers --- // Update Dashboard Button updateBtn.addEventListener("click", function() { renderDashboardTab(); showTab(1); // Switch to Dashboard }); // Add Term addTermBtn.addEventListener("click", function() { var word = termWordInput.value.trim().toUpperCase().replace(/[^A-Z]/g, ''); var clue = termClueInput.value.trim(); if (!word || !clue) { alert("Please provide both a science term (word) and a clue/definition."); return; } var newTerm = { id: Date.now(), word: word, clue: clue }; appState.terms.push(newTerm); renderConfigTab(); // Clear form fields termWordInput.value = ""; termClueInput.value = ""; }); // Remove Term (Event Delegation) termListDiv.addEventListener("click", function(e) { if (e.target.classList.contains("swp-remove-btn")) { var id = parseInt(e.target.dataset.id); appState.terms = appState.terms.filter(function(t) { return t.id !== id; }); renderConfigTab(); } }); // PDF Download pdfBtn.addEventListener("click", function() { var jsPDF = window.jspdf.jsPDF; var titleSlug = titleInput.value.replace(/[^a-zA-Z0-9\s]/g, '').replace(/\s/g, '_').substring(0, 30) || 'Puzzle'; var fileName = `${titleSlug}_Sheets.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("SWP PDF Error:", err); // alert("An error occurred while generating the PDF."); // Per spec }); }); // --- Initial Load --- renderConfigTab(); renderDashboardTab(); showTab(0); // Start on Config tab });
    Scroll to Top