diff --git a/.vscode/settings.json b/.vscode/settings.json new file mode 100644 index 000000000..f673a71b7 --- /dev/null +++ b/.vscode/settings.json @@ -0,0 +1,3 @@ +{ + "liveServer.settings.port": 5502 +} \ No newline at end of file diff --git a/Calculators/Word-Count-Calculator/index.html b/Calculators/Word-Count-Calculator/index.html index 173bc7c75..9e07e8531 100644 --- a/Calculators/Word-Count-Calculator/index.html +++ b/Calculators/Word-Count-Calculator/index.html @@ -15,6 +15,12 @@

+ Total Characters (including space): 0 | + Total Characters (not including space): 0 | + Total Alphabets: 0 | + Total Integers: 0 | + Total Special Characters: 0 +
Total words: 0 | Unique words: 0 | Shortest words: 0 | diff --git a/Calculators/Word-Count-Calculator/script.js b/Calculators/Word-Count-Calculator/script.js index 7bbe99a50..e42728272 100644 --- a/Calculators/Word-Count-Calculator/script.js +++ b/Calculators/Word-Count-Calculator/script.js @@ -1,10 +1,26 @@ -document.addEventListener('DOMContentLoaded', function () { + document.addEventListener('DOMContentLoaded', function () { document.getElementById("inputText").addEventListener("input", countWords); }); function countWords() { var text = document.getElementById("inputText").value; + // calculate total characters including space + var totalCharacterIncludingSpace = text.length; + + // calculate total character not including space + var totalCharacterNotIncludingSpace = text.replace(/\s/g, '').length; + + // calculate total Alphabets + var totalAlphabets = text.replace(/[^a-zA-Z]/g, '').length; + + // calculate total Integers + var totalIntegers = text.replace(/[^0-9]/g, '').length; + + // calculate total special characters + var totalSpecialCharacters = text.replace(/[a-zA-Z0-9\s]/g, '').length; + + // Regex to split the Words var wordsArray = text.split(/\s+/).filter(function (word) { return word.length > 0; @@ -24,6 +40,12 @@ function countWords() { var averageWordLength = calculateAverageWordLength(wordsArray); document.getElementById("result").innerHTML = + "Total Characters (including space): "+ totalCharacterIncludingSpace +" |" + + "Total Characters (not including space): "+totalCharacterNotIncludingSpace+" |"+ + "Total Alphabets: "+totalAlphabets+" |"+ + "Total Integers: "+totalIntegers+" |"+ + "Total Special Characters: "+totalSpecialCharacters+" |"+ + "
"+ "Total words: " + totalWords + " | " + "Unique words: " + uniqueWords + " | " + "Shortest words: " + shortest_count + " | " + @@ -77,8 +99,28 @@ function exportData() { return word.length > 0; }); + + var totalCharacterIncludingSpace = text.length; + + + var totalCharacterNotIncludingSpace = text.replace(/\s/g, '').length; + + + var totalAlphabets = text.replace(/[^a-zA-Z]/g, '').length; + + + var totalIntegers = text.replace(/[^0-9]/g, '').length; + + + var totalSpecialCharacters = text.replace(/[a-zA-Z0-9\s]/g, '').length; + var data = { text: text, + totalCharactersIncludingSpace: totalCharacterIncludingSpace, + totalCharactersNotIncludingSpace: totalCharacterNotIncludingSpace, + totalAlphabets: totalAlphabets, + totalIntegers: totalIntegers, + totalSpecialCharacters: totalSpecialCharacters, totalWords: wordsArray.length, shortestWord: shortestWord(wordsArray).length, longestWord: longestWord(wordsArray).length,