Changed around line 1
+ document.addEventListener('DOMContentLoaded', () => {
+ let selectedAge = null;
+ const generateButton = document.getElementById('generateMaze');
+ const printButton = document.getElementById('printMaze');
+ const mazeGrid = document.getElementById('mazeGrid');
+
+ // Age group selection
+ document.querySelectorAll('.age-buttons button').forEach(button => {
+ button.addEventListener('click', () => {
+ document.querySelectorAll('.age-buttons button').forEach(btn => {
+ btn.classList.remove('selected');
+ });
+ button.classList.add('selected');
+ selectedAge = button.dataset.age;
+ generateButton.disabled = false;
+ printButton.disabled = false;
+ });
+ });
+
+ // Generate maze based on age group
+ generateButton.addEventListener('click', () => {
+ createMaze(selectedAge);
+ });
+
+ // Print maze
+ printButton.addEventListener('click', () => {
+ window.print();
+ });
+
+ function createMaze(ageGroup) {
+ const config = getMazeConfig(ageGroup);
+ const maze = generateMazeData(config);
+ displayMaze(maze);
+ }
+
+ function getMazeConfig(ageGroup) {
+ const configs = {
+ '5-6': {
+ size: 3,
+ operations: ['+'],
+ maxNumber: 10
+ },
+ '7-8': {
+ size: 4,
+ operations: ['+', '-'],
+ maxNumber: 20
+ },
+ '9-10': {
+ size: 5,
+ operations: ['+', '-', '*'],
+ maxNumber: 50
+ },
+ '11-12': {
+ size: 6,
+ operations: ['+', '-', '*', '/'],
+ maxNumber: 100
+ }
+ };
+ return configs[ageGroup];
+ }
+
+ function generateMazeData(config) {
+ const maze = [];
+ for (let i = 0; i < config.size; i++) {
+ const row = [];
+ for (let j = 0; j < config.size; j++) {
+ row.push(generateMathProblem(config));
+ }
+ maze.push(row);
+ }
+ return maze;
+ }
+
+ function generateMathProblem(config) {
+ const operation = config.operations[Math.floor(Math.random() * config.operations.length)];
+ let num1, num2, answer;
+
+ switch (operation) {
+ case '+':
+ num1 = Math.floor(Math.random() * config.maxNumber);
+ num2 = Math.floor(Math.random() * (config.maxNumber - num1));
+ answer = num1 + num2;
+ return `${num1} + ${num2} = ${answer}`;
+ case '-':
+ num1 = Math.floor(Math.random() * config.maxNumber);
+ num2 = Math.floor(Math.random() * num1);
+ answer = num1 - num2;
+ return `${num1} - ${num2} = ${answer}`;
+ case '*':
+ num1 = Math.floor(Math.random() * Math.sqrt(config.maxNumber));
+ num2 = Math.floor(Math.random() * Math.sqrt(config.maxNumber));
+ answer = num1 * num2;
+ return `${num1} × ${num2} = ${answer}`;
+ case '/':
+ num2 = Math.floor(Math.random() * Math.sqrt(config.maxNumber)) + 1;
+ answer = Math.floor(Math.random() * Math.sqrt(config.maxNumber));
+ num1 = num2 * answer;
+ return `${num1} ÷ ${num2} = ${answer}`;
+ }
+ }
+
+ function displayMaze(maze) {
+ mazeGrid.style.gridTemplateColumns = `repeat(${maze.length}, 1fr)`;
+ mazeGrid.innerHTML = '';
+
+ maze.forEach((row, i) => {
+ row.forEach((cell, j) => {
+ const cellElement = document.createElement('div');
+ cellElement.className = 'maze-cell';
+ cellElement.textContent = cell;
+ mazeGrid.appendChild(cellElement);
+ });
+ });
+ }
+ });