From 0200c4e834c29138c202ef237095d1e21f6e2fab Mon Sep 17 00:00:00 2001 From: Aswini Samantray Date: Wed, 10 May 2023 20:18:12 +0530 Subject: [PATCH 1/4] Added the feature to display the longest word in text and the length of the longest word --- Public/word-count-calculator.html | 12 ++++++++---- assets/Js/word-count-calculator.js | 17 +++++++++++++++++ 2 files changed, 25 insertions(+), 4 deletions(-) diff --git a/Public/word-count-calculator.html b/Public/word-count-calculator.html index 7d6fc0fd..6faeae7e 100644 --- a/Public/word-count-calculator.html +++ b/Public/word-count-calculator.html @@ -2,10 +2,12 @@ - Word length calculator + Text Analyzer + + @@ -19,18 +21,20 @@ +
- +
- Count of following parameters is displayed here- +

Your text summary

- +
+
diff --git a/assets/Js/word-count-calculator.js b/assets/Js/word-count-calculator.js index 6d68c03b..026e5a7d 100644 --- a/assets/Js/word-count-calculator.js +++ b/assets/Js/word-count-calculator.js @@ -16,11 +16,25 @@ function count_alphabets(val){ return 0; } +function longest(val){ + + let sentence=val.split(" "); + let longestWord=sentence.reduce(function(a,b){ + if(a.length>b.length) return a; + return b; + },""); + return longestWord; +} +// var temp=document.getElementById("textcontent"); +temp=document.getElementById("textcontent"); var textContent = document.getElementById("textcontent"); var showWordCount = document.getElementById("countWord"); var showcharactercount = document.getElementById("countcharacter"); var showalphabetcount = document.getElementById("countalphabets"); +var longestWord=document.getElementById("longestWord"); +var longestWordlength=document.getElementById("longestWordlength"); textContent.addEventListener("input", function(){ + var v = count_word( this.value ); showWordCount.innerHTML = ( "
Words: "+ v.words @@ -33,4 +47,7 @@ var d = count_alphabets(this.value); showalphabetcount.innerHTML = ( "
Alphabets: "+d ); +var l=longest(this.value); +longestWord.innerHTML=("
Longest Word: "+l); +longestWordlength.innerHTML=("
Length of "+l+" is: "+l.length); }, false); \ No newline at end of file From 4b9dafc2aedcfdef773a382aadc8641d399ec06f Mon Sep 17 00:00:00 2001 From: Aswini Samantray Date: Sat, 10 Jun 2023 21:57:36 +0530 Subject: [PATCH 2/4] Added the feature to know the frequency of a word in text. --- Public/word-count-calculator.html | 12 ++++++++ assets/Js/word-count-calculator.js | 46 +++++++++++++++++++++++++++--- 2 files changed, 54 insertions(+), 4 deletions(-) diff --git a/Public/word-count-calculator.html b/Public/word-count-calculator.html index 6faeae7e..8472ef31 100644 --- a/Public/word-count-calculator.html +++ b/Public/word-count-calculator.html @@ -30,13 +30,25 @@

Your text summary

+
+
+ + +
+ +
diff --git a/assets/Js/word-count-calculator.js b/assets/Js/word-count-calculator.js index 026e5a7d..fc55d607 100644 --- a/assets/Js/word-count-calculator.js +++ b/assets/Js/word-count-calculator.js @@ -25,14 +25,37 @@ function longest(val){ },""); return longestWord; } -// var temp=document.getElementById("textcontent"); -temp=document.getElementById("textcontent"); + +function search(val,search){ + let sentence=val.split(" "); + let count=0; + if(search=='') + return 0; + for(let i=0;iThere is no text."); textContent.addEventListener("input", function(){ var v = count_word( this.value ); @@ -48,6 +71,21 @@ showalphabetcount.innerHTML = ( "
Alphabets: "+d ); var l=longest(this.value); -longestWord.innerHTML=("
Longest Word: "+l); +if(l.length===0){ + longestWord.innerHTML=("
There is no text."); +} +else{ + longestWord.innerHTML=("
Longest Word: "+l.bold()); +} + longestWordlength.innerHTML=("
Length of "+l+" is: "+l.length); -}, false); \ No newline at end of file +let text=this.value; + searchText.addEventListener("input",function(){ + let word=this.value; + f=search(text,word); + searchButton.addEventListener("click",function(){ + frequency.innerHTML=("
"+word.bold()+" occurs "+f+" times(s) in the text."); + },false); + },false); +}, false); + From 94a12a9a9fafb91dadced8afa42dabdbd8487028 Mon Sep 17 00:00:00 2001 From: Aswini Samantray Date: Sat, 10 Jun 2023 21:59:53 +0530 Subject: [PATCH 3/4] minor changes --- assets/Js/word-count-calculator.js | 1 - 1 file changed, 1 deletion(-) diff --git a/assets/Js/word-count-calculator.js b/assets/Js/word-count-calculator.js index fc55d607..d46fe48d 100644 --- a/assets/Js/word-count-calculator.js +++ b/assets/Js/word-count-calculator.js @@ -43,7 +43,6 @@ function search(val,search){ return val; } -// temp=document.getElementById("textcontent"); var textContent = document.getElementById("textcontent"); var showWordCount = document.getElementById("countWord"); var showcharactercount = document.getElementById("countcharacter"); From 4cc696747b45d3d15068827659736f52de0ed216 Mon Sep 17 00:00:00 2001 From: Aswini Samantray Date: Mon, 12 Jun 2023 21:09:26 +0530 Subject: [PATCH 4/4] fixed the search problem --- Public/word-count-calculator.html | 4 ---- assets/Js/word-count-calculator.js | 13 ++++--------- 2 files changed, 4 insertions(+), 13 deletions(-) diff --git a/Public/word-count-calculator.html b/Public/word-count-calculator.html index 8472ef31..e64465d4 100644 --- a/Public/word-count-calculator.html +++ b/Public/word-count-calculator.html @@ -44,10 +44,6 @@

Your text summary

- - -
-
diff --git a/assets/Js/word-count-calculator.js b/assets/Js/word-count-calculator.js index d46fe48d..bbdfeee4 100644 --- a/assets/Js/word-count-calculator.js +++ b/assets/Js/word-count-calculator.js @@ -39,9 +39,6 @@ function search(val,search){ return count; } - function copy(val){ - return val; -} var textContent = document.getElementById("textcontent"); var showWordCount = document.getElementById("countWord"); @@ -54,6 +51,7 @@ var frequency=document.getElementById("frequency"); var copy=document.getElementById("copyButton"); var paste=document.getElementById("pasteButton"); let f=0; + longestWord.innerHTML=("
There is no text."); textContent.addEventListener("input", function(){ @@ -76,15 +74,12 @@ if(l.length===0){ else{ longestWord.innerHTML=("
Longest Word: "+l.bold()); } - -longestWordlength.innerHTML=("
Length of "+l+" is: "+l.length); let text=this.value; - searchText.addEventListener("input",function(){ - let word=this.value; - f=search(text,word); +longestWordlength.innerHTML=("
Length of "+l+" is: "+l.length); searchButton.addEventListener("click",function(){ + let word=searchText.value; + f=search(text,word); frequency.innerHTML=("
"+word.bold()+" occurs "+f+" times(s) in the text."); },false); - },false); }, false);