WORD AND CHARACTER COUNTER
Word and Character Counter
Word and Character Counter
/* styles.css */
body {
font-family: Arial, sans-serif;
background-color: #f0f0f0;
margin: 0;
padding: 0;
display: flex;
justify-content: center;
align-items: center;
height: 100vh;
}
.container {
background-color: #ffffff;
padding: 20px;
border-radius: 10px;
box-shadow: 0 0 10px rgba(0, 0, 0, 0.1);
width: 90%;
max-width: 600px;
text-align: center;
}
h1 {
color: #333333;
}
textarea {
width: 100%;
height: 150px;
padding: 10px;
border: 1px solid #dddddd;
border-radius: 5px;
font-size: 16px;
margin-bottom: 20px;
}
.counts {
display: flex;
justify-content: space-between;
}
p {
font-size: 18px;
margin: 0;
}
span {
font-weight: bold;
}
// script.js
document.getElementById('text-input').addEventListener('input', updateCounts);
function updateCounts() {
const text = document.getElementById('text-input').value;
const wordCount = countWords(text);
const charCount = countCharacters(text);
document.getElementById('word-count').innerText = wordCount;
document.getElementById('char-count').innerText = charCount;
}
function countWords(text) {
const words = text.trim().split(/\s+/);
return words.filter(word => word.length > 0).length;
}
function countCharacters(text) {
return text.length;
}
No comments:
Post a Comment