mirror of
https://github.com/Alvin-Zilverstand/ict-algemeen-opdrachten.git
synced 2026-03-06 02:57:05 +01:00
Add Woordenteller application with HTML, CSS, and JavaScript implementation
This commit is contained in:
17
JavaScript/woordenteller/index.html
Normal file
17
JavaScript/woordenteller/index.html
Normal 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>
|
||||
41
JavaScript/woordenteller/style.css
Normal file
41
JavaScript/woordenteller/style.css
Normal 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;
|
||||
}
|
||||
34
JavaScript/woordenteller/woordenteller.js
Normal file
34
JavaScript/woordenteller/woordenteller.js
Normal 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);
|
||||
});
|
||||
Reference in New Issue
Block a user