File tree Expand file tree Collapse file tree 1 file changed +64
-0
lines changed
Expand file tree Collapse file tree 1 file changed +64
-0
lines changed Original file line number Diff line number Diff line change 1+ function getVowelCount ( sentence ) {
2+ const vowels = "aeiou" ;
3+ let count = 0 ;
4+
5+ for ( const char of sentence . toLowerCase ( ) ) {
6+ if ( vowels . includes ( char ) ) {
7+ count ++ ;
8+ }
9+ }
10+ return count ;
11+ }
12+
13+ const vowelCount = getVowelCount ( "Apples are tasty fruits" ) ;
14+ console . log ( `Vowel Count: ${ vowelCount } ` ) ;
15+
16+ function getConsonantCount ( sentence ) {
17+ const consonants = "bcdfghjklmnpqrstvwxyz" ;
18+ let count = 0 ;
19+
20+ for ( const char of sentence . toLowerCase ( ) ) {
21+ if ( consonants . includes ( char ) ) {
22+ count ++ ;
23+ }
24+ }
25+ return count ;
26+ }
27+
28+ const consonantCount = getConsonantCount ( "Coding is fun" ) ;
29+ console . log ( `Consonant Count: ${ consonantCount } ` ) ;
30+
31+ function getPunctuationCount ( sentence ) {
32+ const punctuations = ".,!?;:-()[]{}\"'–" ;
33+ let count = 0 ;
34+
35+ for ( const char of sentence ) {
36+ if ( punctuations . includes ( char ) ) {
37+ count ++ ;
38+ }
39+ }
40+ return count ;
41+ }
42+
43+ const punctuationCount = getPunctuationCount ( "WHAT?!?!?!?!?" ) ;
44+ console . log ( `Punctuation Count: ${ punctuationCount } ` ) ;
45+
46+ function getWordCount ( sentence ) {
47+ if ( sentence . trim ( ) === '' ) {
48+ return 0 ;
49+ }
50+
51+ const words = sentence . trim ( ) . split ( ' ' ) ;
52+ let count = 0 ;
53+
54+ for ( const word of words ) {
55+ if ( word !== '' ) {
56+ count ++ ;
57+ }
58+ }
59+
60+ return count ;
61+ }
62+
63+ const wordCount = getWordCount ( "I love freeCodeCamp" ) ;
64+ console . log ( `Word Count: ${ wordCount } ` ) ;
You can’t perform that action at this time.
0 commit comments