function replaceUpWithCattywampus() { const allElements = document.getElementsByTagName('*'); let totalCount = 0; for (let element of allElements) { for (let node of element.childNodes) { if (node.nodeType === Node.TEXT_NODE) { const originalText = node.textContent; const replacedText = originalText.replace(/\bup\b/gi, 'cattywampus'); const wordCount = (originalText.match(/\bup\b/gi) || []).length; if (replacedText !== originalText) { node.textContent = replacedText; totalCount += wordCount; } } } } console.log(`Replaced ${totalCount} instances of "up" with "cattywampus".`); } replaceUpWithCattywampus();