@@ -16,11 +16,45 @@ function count_alphabets(val){
1616 return 0 ;
1717}
1818
19+ function longest ( val ) {
20+
21+ let sentence = val . split ( " " ) ;
22+ let longestWord = sentence . reduce ( function ( a , b ) {
23+ if ( a . length > b . length ) return a ;
24+ return b ;
25+ } , "" ) ;
26+ return longestWord ;
27+ }
28+
29+ function search ( val , search ) {
30+ let sentence = val . split ( " " ) ;
31+ let count = 0 ;
32+ if ( search == '' )
33+ return 0 ;
34+ for ( let i = 0 ; i < sentence . length ; i ++ ) {
35+ if ( sentence [ i ] == search && sentence [ sentence . length - 1 ] != " " ) {
36+ count = count + 1 ;
37+ }
38+ }
39+ return count ;
40+ }
41+
42+
1943var textContent = document . getElementById ( "textcontent" ) ;
2044var showWordCount = document . getElementById ( "countWord" ) ;
2145var showcharactercount = document . getElementById ( "countcharacter" ) ;
2246var showalphabetcount = document . getElementById ( "countalphabets" ) ;
47+ var longestWord = document . getElementById ( "longestWord" ) ;
48+ var longestWordlength = document . getElementById ( "longestWordlength" ) ;
49+ var searchText = document . getElementById ( "searchText" ) ; //Word to be searched
50+ var frequency = document . getElementById ( "frequency" ) ;
51+ var copy = document . getElementById ( "copyButton" ) ;
52+ var paste = document . getElementById ( "pasteButton" ) ;
53+ let f = 0 ;
54+
55+ longestWord . innerHTML = ( "<br>There is no text." ) ;
2356textContent . addEventListener ( "input" , function ( ) {
57+
2458var v = count_word ( this . value ) ;
2559showWordCount . innerHTML = (
2660 "<br>Words: " + v . words
@@ -33,4 +67,19 @@ var d = count_alphabets(this.value);
3367showalphabetcount . innerHTML = (
3468 "<br>Alphabets: " + d
3569) ;
36- } , false ) ;
70+ var l = longest ( this . value ) ;
71+ if ( l . length === 0 ) {
72+ longestWord . innerHTML = ( "<br>There is no text." ) ;
73+ }
74+ else {
75+ longestWord . innerHTML = ( "<br>Longest Word: " + l . bold ( ) ) ;
76+ }
77+ let text = this . value ;
78+ longestWordlength . innerHTML = ( "<br>Length of " + l + " is: " + l . length ) ;
79+ searchButton . addEventListener ( "click" , function ( ) {
80+ let word = searchText . value ;
81+ f = search ( text , word ) ;
82+ frequency . innerHTML = ( "<br>" + word . bold ( ) + " occurs " + f + " times(s) in the text." ) ;
83+ } , false ) ;
84+ } , false ) ;
85+
0 commit comments