Scientific Method Worksheet Generator

Scientific Method Worksheet Generator

1. Project Details
2. Scientific Method Steps

SCIENTIFIC METHOD WORKSHEET

Project | Researcher | Dates

Click "Generate Worksheet" to preview your structured plan.

Customize Scientific Method Steps

Edit the labels and descriptions for each step to fit your project's needs.

Step ID Title (Editable) Description/Prompt (Editable)

${step.desc}

`; methodStepsArea.appendChild(container); }); }; // --- Tab 3: Configuration Management --- const renderConfigTable = () => { configTableBody.innerHTML = ''; methodSteps.forEach(step => { const row = document.createElement('tr'); row.innerHTML = ` ${step.id} `; configTableBody.appendChild(row); }); }; window.updateStepConfig = (id, field, value) => { const step = methodSteps.find(s => s.id === id); if (step) { step[field] = value; // Update builder tab immediately renderBuilderSteps(); } }; resetStepsBtn.addEventListener('click', () => { if (confirm('Are you sure you want to reset all steps to the default Scientific Method structure?')) { methodSteps = JSON.parse(JSON.stringify(defaultSteps)); renderConfigTable(); renderBuilderSteps(); } }); // --- Tab 2: Review & PDF Functions --- const collectWorksheetContent = () => { const content = {}; methodSteps.forEach(step => { const textarea = document.getElementById(`content-${step.id}`); content[step.id] = textarea ? textarea.value : ''; }); return content; }; const generateWorksheet = () => { const meta = getMeta(); const content = collectWorksheetContent(); pdfDownloadBtn.disabled = !meta.projectName; // Disable if no project name // 1. Update Review Header reviewTitleEl.textContent = `SCIENTIFIC METHOD WORKSHEET: ${meta.projectName.toUpperCase()}`; reviewMetaEl.textContent = `Researcher: ${meta.researcherName} | Dates: ${formatDate(meta.dateStart)} - ${formatDate(meta.dateEnd)}`; // 2. Update Review Steps Content reviewStepsContent.innerHTML = ''; if (!meta.projectName) { reviewStepsContent.innerHTML = '

Please enter project details in the Builder tab.

'; return; } methodSteps.forEach((step, index) => { const container = document.createElement('div'); container.className = 'review-step'; container.innerHTML = `

${index + 1}. ${step.title}

${content[step.id] || 'N/A (No content provided for this step.)'}
`; reviewStepsContent.appendChild(container); }); // Only switch tab if the button was explicitly pressed if (document.activeElement === generateWorksheetBtn) { switchTab(1); } }; const downloadPDF = () => { const meta = getMeta(); const content = collectWorksheetContent(); const { jsPDF } = window.jspdf; const doc = new jsPDF('p', 'pt', 'a4'); let currentY = 40; const margin = 40; const pageWidth = doc.internal.pageSize.width; const checkPageBreak = (spaceNeeded) => { if (currentY + spaceNeeded > doc.internal.pageSize.height - margin) { doc.addPage(); currentY = margin; } }; // Helper to add text and manage Y position const addText = (text, size = 11, style = 'normal', color = [0, 0, 0], indent = 0) => { doc.setFontSize(size); doc.setFont('Helvetica', style); doc.setTextColor(color[0], color[1], color[2]); const lines = doc.splitTextToSize(text, pageWidth - margin * 2 - indent); checkPageBreak(lines.length * (size * 1.2)); doc.text(lines, margin + indent, currentY); currentY += (lines.length * (size * 1.2)); doc.setTextColor(0); // Reset color }; // --- PDF Header --- doc.setFontSize(20); doc.setFont('Helvetica', 'bold'); doc.setTextColor(0, 123, 255); doc.text(`SCIENTIFIC METHOD WORKSHEET`, pageWidth / 2, currentY, { align: 'center' }); currentY += 10; doc.setFontSize(14); doc.text(meta.projectName.toUpperCase(), pageWidth / 2, currentY, { align: 'center' }); currentY += 15; doc.setFontSize(10); doc.setFont('Helvetica', 'normal'); doc.setTextColor(108, 117, 125); doc.text(`Researcher: ${meta.researcherName} | Dates: ${formatDate(meta.dateStart)} - ${formatDate(meta.dateEnd)}`, pageWidth / 2, currentY, { align: 'center' }); currentY += 30; doc.setTextColor(0); // --- Steps Content --- methodSteps.forEach((step, index) => { checkPageBreak(40); // Space for title and initial content // Step Title doc.setFontSize(14); doc.setFont('Helvetica', 'bold'); doc.setTextColor(23, 162, 184); /* Info color */ doc.text(`${index + 1}. ${step.title}`, margin, currentY); currentY += 10; // Content doc.setDrawColor(222, 226, 230); // Border color doc.setLineWidth(1); const stepContent = content[step.id] || 'N/A (No content provided for this step.)'; // Estimate height of content block for box drawing const lines = doc.splitTextToSize(stepContent, maxWidth - 10); // Content is indented 10 const contentHeight = (lines.length * 10) + 10; // Draw box (simulated background) doc.setFillColor(241, 241, 241); doc.rect(margin, currentY, maxWidth, contentHeight, 'F'); doc.setFontSize(11); doc.setFont('Helvetica', 'normal'); doc.setTextColor(51); doc.text(lines, margin + 5, currentY + 7); currentY += contentHeight + 15; // Move down after content block }); doc.save(`${meta.projectName.replace(/\s/g, '_')}_Worksheet.pdf`); } // --- Tab Navigation --- const switchTab = (tabIndex) => { tabs.forEach((tab, index) => { tab.classList.toggle('active', index === tabIndex); contents[index].classList.toggle('active', index === tabIndex); }); currentTab = tabIndex; updateNavButtons(); if (tabIndex === 1) { // Review tab generateWorksheet(); } } const updateNavButtons = () => { prevBtn.disabled = currentTab === 0; nextBtn.disabled = currentTab === tabs.length - 1; } // Attach listeners to tab buttons tabs.forEach((tab, index) => { tab.addEventListener('click', () => { // Find actual index based on position in DOM const tabNode = tab.closest('.worksheet-tab-button'); const newIndex = Array.from(tabNode.parentNode.children).indexOf(tabNode); switchTab(newIndex); }); }); nextBtn.addEventListener('click', () => { if (currentTab < tabs.length - 1) switchTab(currentTab + 1); }); prevBtn.addEventListener('click', () => { if (currentTab > 0) switchTab(currentTab - 1); }); // --- Event Listeners --- generateWorksheetBtn.addEventListener('click', () => { // Run generation and switch to review tab generateWorksheet(); switchTab(1); }); pdfDownloadBtn.addEventListener('click', downloadPDF); // FIX: Ensure metaForm is defined before attaching listener if (metaForm) { metaForm.addEventListener('input', generateWorksheet); // Update preview on meta change } // --- Initial Setup --- const today = new Date(); const yyyy = today.getFullYear(); const mm = String(today.getMonth() + 1).padStart(2, '0'); const dd = String(today.getDate()).padStart(2, '0'); dateStartInput.value = `${yyyy}-${mm}-${dd}`; renderConfigTable(); renderBuilderSteps(); updateNavButtons(); generateWorksheet(); });
Scroll to Top