Word Problem Generator

Word Problem Generator

Generate complex, solvable mathematical word problems for practice or teaching.

Problem Configuration

Generated Word Problem

Use the configuration panel above to generate your first word problem.

${escapeHtml(problemText)}

Question: [See prompt text]

`; // Hide solution by default wpgShowSolution(false); }; window.wpgShowSolution = function(show) { const solutionBox = document.getElementById('wpg-solution-display'); if (solutionBox) { solutionBox.classList.toggle('hidden', !show); } }; // --- PDF Download --- window.wpgDownloadPDF = function() { // Ensure problem is generated if (lastProblem.text === "Problem not yet generated.") { wpgGenerateProblem(); } const element = document.getElementById('wpg-print-area'); // Ensure solution is visible for PDF generation wpgShowSolution(true); document.body.classList.add('wpg-generating-pdf'); const opt = { margin: [0.5, 0.5], filename: `Word_Problem_Sheet_${new Date().toISOString().split('T')[0]}.pdf`, image: { type: 'jpeg', quality: 0.98 }, html2canvas: { scale: 2, useCORS: true }, jsPDF: { unit: 'in', format: 'letter', orientation: 'portrait' } }; html2pdf().set(opt).from(element).save().then(() => { document.body.classList.remove('wpg-generating-pdf'); // Re-hide solution after PDF generation wpgShowSolution(false); }); }; // Utility: HTML Escape function escapeHtml(text) { if (!text) return ''; // Use monospace font to display the code/math cleanly if (text.startsWith('\nFormula')) { return text; // Already formatted as pre-wrap content } return text.replace(/[&<>"']/g, function(m) { switch (m) { case '&': return '&'; case '<': return '<'; case '>': return '>'; case '"': return '"'; case "'": return '''; default: return m; } }); }
Scroll to Top