-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy path12-CoderByte-Vowel-Count.js
More file actions
28 lines (25 loc) · 989 Bytes
/
12-CoderByte-Vowel-Count.js
File metadata and controls
28 lines (25 loc) · 989 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
//Vowel Count
//Using the JavaScript language, have the function VowelCount(str) take the str string parameter being passed
//and return the number of vowels the string contains (ie. "All cows eat grass" would return 5). Do not count
//y as a vowel for this challenge.
function vowelCount(str) {
var strSplit = str.toUpperCase().split('');
var count = 0;
for (var i = 0; i < strSplit.length; i++){
if (strSplit[i] === "A") {
count++
} else if (strSplit[i] === "E") {
count++
} else if (strSplit[i] === "I") {
count++
} else if (strSplit[i] === "O") {
count++
} else if (strSplit[i] === "U")
count++
}
// code goes here
return count;
};
//Takes a string, capitalizes everything and split it into an array of characters.
//Then loop through strSplit checking for vowels if there is one then increase the count by 1
//There's probably a way better way to do this.