forked from CodeToExpress/dailycodebase
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathpartA_sol1.js
More file actions
25 lines (21 loc) Β· 775 Bytes
/
partA_sol1.js
File metadata and controls
25 lines (21 loc) Β· 775 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
// Step 1: Set count = 0
// Step 2: Run a loop from i=0 to i=string_length
// Step 3: In each iteration check whether the character at position i is βaβ, βeβ, βiβ, βoβ, or βuβ. If the condition passes, increment the value of count.
// Step 4: Print and return the results.
function numVowels (str) {
let count = 0;
for (let i=0; i<str.length; i++) {
if (
str[i].toLowerCase() === 'a' ||
str[i].toLowerCase() === 'e' ||
str[i].toLowerCase() === 'i' ||
str[i].toLowerCase() === 'o' ||
str[i].toLowerCase() === 'u'
) {
count++;
}
}
console.log (`The number of vowels in ${str} is = ${count}`);
}
numVowels ('hello');
numVowels ('Greetings');