Skip to content

Commit 4ad9958

Browse files
committed
Create Vowel Count
1 parent e4092fa commit 4ad9958

File tree

1 file changed

+39
-0
lines changed

1 file changed

+39
-0
lines changed

Vowel Count

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
/***************************************************************************************
2+
* *
3+
* CODERBYTE BEGINNER CHALLENGE *
4+
* *
5+
* Vowel Count *
6+
* Using the JavaScript language, have the function VowelCount(str) take the str *
7+
* string parameter being passed and return the number of vowels the string contains *
8+
* (ie. "All cows eat grass" would return 5). Do not count y as a vowel for this *
9+
* challenge. *
10+
* *
11+
* SOLUTION *
12+
* I will be using two for loops that will be nested. I will be searching thru all *
13+
* entries in my vowel array in the outter loop and searching through each letter *
14+
* in the string in the inner loop. I will be comparing each vowel to every letter *
15+
* in the string. If it matches then I will be incrememting by total by 1.
16+
* *
17+
* Steps for solution *
18+
* 1) create my vowel arrray. *
19+
* 2) Initialize tot to zero. *
20+
* 3) Loop through each vowel and compare to each letter in string *
21+
* 4) If match then increment tot by 1 *
22+
* 5) Return tot as answer *
23+
* *
24+
***************************************************************************************/
25+
function VowelCount(str) {
26+
27+
var vowelArr = ["a","e","i","o","u"];
28+
var tot = 0;
29+
30+
for (var i = 0; i < vowelArr.length; i++) {
31+
for (var j = 0; j < str.length; j++) {
32+
if (str[j] === vowelArr[i]) {
33+
tot++;
34+
}
35+
}
36+
}
37+
return tot;
38+
39+
}

0 commit comments

Comments
 (0)