Best Free Word Search Maker for Kids

Share this post

Try Our Tools

Leave a Comment

Your email address will not be published. Required fields are marked *

Scroll to Top
'); newWindow.document.close(); newWindow.focus(); setTimeout(() => { newWindow.print(); newWindow.close(); }, 1000); // Adjust timeout as needed for content to load before printing }function printAnswerKey() { const boardElement = document.getElementById('board').cloneNode(true);// Highlight the answer key boardElement.querySelectorAll('.cell').forEach(cell => cell.classList.remove('answer')); wordPositions.forEach(({ positions }) => { positions.forEach(({ row, col }) => { const cell = boardElement.querySelector(`.cell[data-row="${row}"][data-col="${col}"]`); cell.classList.add('answer'); }); });// Adjusting styles for printing const style = ``;const newWindow = window.open('', '', 'width=600,height=400'); newWindow.document.write('Print Answer Key' + style + ''); newWindow.document.write('

Word Search Answer Key

'); newWindow.document.write('
' + boardElement.outerHTML + '
'); newWindow.document.write('

My Baby Fitness

'); newWindow.document.write(''); newWindow.document.close(); newWindow.focus(); setTimeout(() => { newWindow.print(); newWindow.close(); }, 1000); // Adjust timeout as needed for content to load before printing }function toggleAnswerKey() { showAnswers = !showAnswers; const cells = document.querySelectorAll('.cell'); cells.forEach(cell => { const row = parseInt(cell.dataset.row); const col = parseInt(cell.dataset.col); if (showAnswers && isPartOfWord(row, col)) { cell.classList.add('answer'); } else { cell.classList.remove('answer'); } }); updateAnswerKeyButton(); }function isPartOfWord(row, col) { for (const word of words) { if (checkWordInDirection(word, row, col, 1, 0) || checkWordInDirection(word, row, col, 0, 1) || checkWordInDirection(word, row, col, 1, 1) || checkWordInDirection(word, row, col, -1, 1) || checkWordInDirection(word, row, col, -1, 0) || checkWordInDirection(word, row, col, 0, -1) || checkWordInDirection(word, row, col, -1, -1) || checkWordInDirection(word, row, col, 1, -1)) { return true; } } return false; }function checkWordInDirection(word, row, col, dx, dy) { for (let i = 0; i < word.length; i++) { const newRow = row + i * dy; const newCol = col + i * dx; if (newRow < 0 || newRow >= boardSize || newCol < 0 || newCol >= boardSize || board[newRow][newCol] !== word[i]) { return false; } } return true; }function updateAnswerKeyButton() { const button = document.querySelector('button[onclick="toggleAnswerKey()"]'); button.textContent = showAnswers ? 'Hide Answer Key' : 'Show Answer Key'; }function clearMessage() { const messageElement = document.getElementById('message'); messageElement.textContent = ''; }function displayMessage(message) { const messageElement = document.getElementById('message'); messageElement.textContent = message; }/* Word search scripts: */let boardSize = 15; let board = []; let words = []; let foundWords = []; let selectedCells = []; let showAnswers = false; let wordPositions = []; /* function initializeGame() { boardSize = parseInt(document.getElementById('gridSize').value) || 15; const wordList = document.getElementById('wordList').value; words = wordList.split(',').map(word => word.trim().toUpperCase()); if (words.length === 0) { alert('Please enter at least one word.'); return; } foundWords = []; wordPositions = []; generateBoard(); renderBoard(); displayWords(); clearMessage(); showAnswers = false; updateAnswerKeyButton(); } */function initializeGame() { boardSize = parseInt(document.getElementById('gridSize').value) || 15; const wordList = document.getElementById('wordList').value; words = wordList.split(',').map(word => word.replace(/\s+/g, '').toUpperCase()); if (words.length === 0) { alert('Please enter at least one word.'); return; } foundWords = []; wordPositions = []; generateBoard(); renderBoard(); displayWords(); clearMessage(); showAnswers = false; updateAnswerKeyButton(); }function generateBoard() { board = Array.from({ length: boardSize }, () => Array(boardSize).fill('')); document.getElementById('board').style.gridTemplateColumns = `repeat(${boardSize}, 30px)`;for (const word of words) { if (!placeWord(word)) { alert('Error placing word: ' + word); } }for (let i = 0; i < boardSize; i++) { for (let j = 0; j < boardSize; j++) { if (board[i][j] === '') { board[i][j] = String.fromCharCode(65 + Math.floor(Math.random() * 26)); } } } }function placeWord(word) { const directions = [ { x: 1, y: 0 }, // horizontal { x: 0, y: 1 }, // vertical { x: 1, y: 1 }, // diagonal down-right { x: -1, y: 1 }, // diagonal down-left { x: -1, y: 0 }, // horizontal backward { x: 0, y: -1 }, // vertical backward { x: -1, y: -1 }, // diagonal up-left { x: 1, y: -1 } // diagonal up-right ];for (let attempt = 0; attempt < 100; attempt++) { const direction = directions[Math.floor(Math.random() * directions.length)]; const row = Math.floor(Math.random() * boardSize); const col = Math.floor(Math.random() * boardSize);if (canPlaceWord(word, row, col, direction)) { const positions = []; for (let i = 0; i < word.length; i++) { board[row + i * direction.y][col + i * direction.x] = word[i]; positions.push({ row: row + i * direction.y, col: col + i * direction.x }); } wordPositions.push({ word, positions }); return true; } }return false; }function canPlaceWord(word, row, col, direction) { for (let i = 0; i < word.length; i++) { const newRow = row + i * direction.y; const newCol = col + i * direction.x; if (newRow < 0 || newRow >= boardSize || newCol < 0 || newCol >= boardSize || (board[newRow][newCol] !== '' && board[newRow][newCol] !== word[i])) { return false; } } return true; }function renderBoard() { const boardElement = document.getElementById('board'); boardElement.innerHTML = ''; for (let i = 0; i < boardSize; i++) { for (let j = 0; j < boardSize; j++) { const cell = document.createElement('div'); cell.className = 'cell'; cell.textContent = board[i][j]; cell.dataset.row = i; cell.dataset.col = j; cell.addEventListener('click', () => selectCell(cell, i, j)); boardElement.appendChild(cell); } } }function selectCell(cell, row, col) { if (cell.classList.contains('highlight')) { cell.classList.remove('highlight'); selectedCells = selectedCells.filter(c => !(c.row === row && c.col === col)); } else { cell.classList.add('highlight'); selectedCells.push({ row, col, letter: board[row][col] }); } checkSelectedWord(); } /* function checkSelectedWord() { const selectedWord = selectedCells.map(c => c.letter).join(''); const reversedWord = selectedCells.map(c => c.letter).reverse().join('');if (words.includes(selectedWord) || words.includes(reversedWord)) { selectedCells.forEach(c => { const cell = document.querySelector(`.cell[data-row="${c.row}"][data-col="${c.col}"]`); cell.classList.remove('highlight'); cell.classList.add('found'); }); foundWords.push(selectedWord); selectedCells = []; updateWordCount(); if (foundWords.length === words.length) { displayMessage('Congratulations! You found all the words.'); } } }function displayWords() { const wordsElement = document.getElementById('words'); wordsElement.innerHTML = ''; const ul = document.createElement('ul'); words.forEach(word => { const li = document.createElement('li'); li.textContent = word.replace(/\s+/g, ''); ul.appendChild(li); }); wordsElement.appendChild(ul); }*/function checkSelectedWord() { const selectedWord = selectedCells.map(c => c.letter).join('').replace(/\s+/g, ''); const reversedWord = selectedCells.map(c => c.letter).reverse().join('').replace(/\s+/g, '');if (words.includes(selectedWord) || words.includes(reversedWord)) { selectedCells.forEach(c => { const cell = document.querySelector(`.cell[data-row="${c.row}"][data-col="${c.col}"]`); cell.classList.remove('highlight'); cell.classList.add('found'); }); foundWords.push(selectedWord); selectedCells = []; updateWordCount(); displayWords(); // Update the word list display after finding a word if (foundWords.length === words.length) { displayMessage('Congratulations! You found all the words.'); } } }function displayWords() { const wordsElement = document.getElementById('words'); wordsElement.innerHTML = ''; const ul = document.createElement('ul'); words.forEach(word => { const li = document.createElement('li'); if (foundWords.includes(word)) { li.innerHTML = `${word.replace(/\s+/g, '')}`; } else { li.textContent = word.replace(/\s+/g, ''); } ul.appendChild(li); }); wordsElement.appendChild(ul); }function updateWordCount() { const messageElement = document.getElementById('message'); messageElement.textContent = `Words found: ${foundWords.length} / ${words.length}`; }function shuffleBoard() { initializeGame(); }function showAnswerKey() { wordPositions.forEach(({ positions }) => { positions.forEach(({ row, col }) => { const cell = document.querySelector(`.cell[data-row="${row}"][data-col="${col}"]`); cell.classList.add('answer'); }); }); }function printBoard() { const boardElement = document.getElementById('board').cloneNode(true); const wordsElement = document.getElementById('words').cloneNode(true);// Adjusting styles for printing const style = ``;const newWindow = window.open('', '', 'width=600,height=400'); newWindow.document.write('Print Board' + style + ''); newWindow.document.write('

Word Search Game

'); newWindow.document.write('
' + boardElement.outerHTML + '
'); //newWindow.document.write('
' + wordsElement.outerHTML + '
'); newWindow.document.write('


Words:
    ' + words.join(',     ') + '
'); newWindow.document.write('

My Baby Fitness

'); newWindow.document.write(''); newWindow.document.close(); newWindow.focus(); setTimeout(() => { newWindow.print(); newWindow.close(); }, 1000); // Adjust timeout as needed for content to load before printing }function printAnswerKey() { const boardElement = document.getElementById('board').cloneNode(true);// Highlight the answer key boardElement.querySelectorAll('.cell').forEach(cell => cell.classList.remove('answer')); wordPositions.forEach(({ positions }) => { positions.forEach(({ row, col }) => { const cell = boardElement.querySelector(`.cell[data-row="${row}"][data-col="${col}"]`); cell.classList.add('answer'); }); });// Adjusting styles for printing const style = ``;const newWindow = window.open('', '', 'width=600,height=400'); newWindow.document.write('Print Answer Key' + style + ''); newWindow.document.write('

Word Search Answer Key

'); newWindow.document.write('
' + boardElement.outerHTML + '
'); newWindow.document.write('

My Baby Fitness

'); newWindow.document.write(''); newWindow.document.close(); newWindow.focus(); setTimeout(() => { newWindow.print(); newWindow.close(); }, 1000); // Adjust timeout as needed for content to load before printing }function toggleAnswerKey() { showAnswers = !showAnswers; const cells = document.querySelectorAll('.cell'); cells.forEach(cell => { const row = parseInt(cell.dataset.row); const col = parseInt(cell.dataset.col); if (showAnswers && isPartOfWord(row, col)) { cell.classList.add('answer'); } else { cell.classList.remove('answer'); } }); updateAnswerKeyButton(); }function isPartOfWord(row, col) { for (const word of words) { if (checkWordInDirection(word, row, col, 1, 0) || checkWordInDirection(word, row, col, 0, 1) || checkWordInDirection(word, row, col, 1, 1) || checkWordInDirection(word, row, col, -1, 1) || checkWordInDirection(word, row, col, -1, 0) || checkWordInDirection(word, row, col, 0, -1) || checkWordInDirection(word, row, col, -1, -1) || checkWordInDirection(word, row, col, 1, -1)) { return true; } } return false; }function checkWordInDirection(word, row, col, dx, dy) { for (let i = 0; i < word.length; i++) { const newRow = row + i * dy; const newCol = col + i * dx; if (newRow < 0 || newRow >= boardSize || newCol < 0 || newCol >= boardSize || board[newRow][newCol] !== word[i]) { return false; } } return true; }function updateAnswerKeyButton() { const button = document.querySelector('button[onclick="toggleAnswerKey()"]'); button.textContent = showAnswers ? 'Hide Answer Key' : 'Show Answer Key'; }function clearMessage() { const messageElement = document.getElementById('message'); messageElement.textContent = ''; }function displayMessage(message) { const messageElement = document.getElementById('message'); messageElement.textContent = message; }