Add Woordenteller application with HTML, CSS, and JavaScript implementation

This commit is contained in:
vista-man
2025-01-27 20:29:15 +01:00
parent 05e773e405
commit 078130fc43
3 changed files with 92 additions and 0 deletions

View File

@@ -0,0 +1,17 @@
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Woordenteller</title>
<link rel="stylesheet" href="style.css">
</head>
<body>
<h1>Woordenteller</h1>
<textarea id="textInput" rows="10" cols="50"></textarea><br>
<button id="countButton">Tel Woorden</button>
<div id="result"></div>
<script src="woordenteller.js"></script>
</body>
</html>

View File

@@ -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;
}

View File

@@ -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);
});