diff --git a/JavaScript/woordenteller/index.html b/JavaScript/woordenteller/index.html new file mode 100644 index 0000000..1a626f7 --- /dev/null +++ b/JavaScript/woordenteller/index.html @@ -0,0 +1,17 @@ + + + + + + Woordenteller + + + +

Woordenteller

+
+ +
+ + + + diff --git a/JavaScript/woordenteller/style.css b/JavaScript/woordenteller/style.css new file mode 100644 index 0000000..759ceb5 --- /dev/null +++ b/JavaScript/woordenteller/style.css @@ -0,0 +1,41 @@ +body { + font-family: Arial, sans-serif; + margin: 20px; +} + +h1 { + color: #333; +} + +textarea { + width: 100%; + padding: 10px; + margin-bottom: 10px; + border: 1px solid #ccc; + border-radius: 4px; +} + +button { + padding: 10px 20px; + background-color: #007BFF; + color: white; + border: none; + border-radius: 4px; + cursor: pointer; +} + +button:hover { + background-color: #0056b3; +} + +#result { + margin-top: 20px; +} + +#result p { + background-color: #f8f9fa; + padding: 5px; + border: 1px solid #ddd; + border-radius: 4px; + margin: 5px 0; +} diff --git a/JavaScript/woordenteller/woordenteller.js b/JavaScript/woordenteller/woordenteller.js new file mode 100644 index 0000000..b3a66fd --- /dev/null +++ b/JavaScript/woordenteller/woordenteller.js @@ -0,0 +1,34 @@ +function countWordOccurrences(text) { + const words = text.toLowerCase().match(/\b\w+\b/g); + const wordCount = {}; + + words.forEach(word => { + wordCount[word] = (wordCount[word] || 0) + 1; + }); + + return wordCount; +} + +function displayWordCount(wordCount) { + const resultDiv = document.getElementById('result'); + resultDiv.innerHTML = ''; // Clear previous results + + let totalWords = 0; + for (const [word, count] of Object.entries(wordCount)) { + totalWords += count; + const p = document.createElement('p'); + p.textContent = `${word}: ${count}`; + resultDiv.appendChild(p); + } + + const totalP = document.createElement('p'); + totalP.textContent = `Totaal aantal woorden: ${totalWords}`; + resultDiv.appendChild(totalP); +} + +// Example usage: +document.getElementById('countButton').addEventListener('click', () => { + const text = document.getElementById('textInput').value; + const wordCount = countWordOccurrences(text); + displayWordCount(wordCount); +});