Skip to content

Commit

Permalink
CHAR COUNTER functions now filter blank spaces
Browse files Browse the repository at this point in the history
  • Loading branch information
petry committed Dec 4, 2023
1 parent 4262c39 commit ee6fb4f
Showing 1 changed file with 11 additions and 7 deletions.
18 changes: 11 additions & 7 deletions script.js
Original file line number Diff line number Diff line change
Expand Up @@ -37,20 +37,24 @@ function up() {document.getElementById("luzinha").style.color = "#00ff00"}
//WORDS / CHARACTERS COUNTERS
var inputText = document.getElementById("inputText");
var charCount = document.getElementById("charCount");
var wordCount = document.getElementById("wordCount"); // assuming you have a word count element

window.addEventListener("load",function(){
window.addEventListener("load", function(){
var characters = inputText.value.split('');
charCount.innerText = characters.length;

let wordCountString = document.getElementById("inputText").value.split(" ").length
wordCount.innerText = wordCountString
var words = inputText.value.split(/\s+/).filter(function(word) {
return word.length > 0; // filter out empty strings
});
wordCount.innerText = words.length;
});

inputText.addEventListener("keyup",function(){
inputText.addEventListener("keyup", function(){
var characters = inputText.value.split('');
charCount.innerText = characters.length;

let wordCountString = document.getElementById("inputText").value.split(" ").length
wordCount.innerText = wordCountString
var words = inputText.value.split(/\s+/).filter(function(word) {
return word.length > 0; // filter out empty strings
});
wordCount.innerText = words.length;
});
//END

0 comments on commit ee6fb4f

Please sign in to comment.