Skip to content

Commit 879e0e3

Browse files
committed
renamed the folder
1 parent f582931 commit 879e0e3

File tree

1 file changed

+35
-0
lines changed

1 file changed

+35
-0
lines changed

Vowel_counter_2/iterative_appr.js

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
/*
2+
***********************************************************************************************
3+
Given a string of text containing 0 or more vowels, count the number
4+
of vowels that can be found within the text.
5+
************************************************************************************************
6+
We can breakdown the solution to this challenge in three steps generally:
7+
1.We write a function that’d receive a parameter called text. It would
8+
be a string of any length which would be passed to the function as an argument when it is called.
9+
2.Next, within the function we have to go through the text and search for occurrences of the English
10+
vowels (a,e,i,o,u).
11+
3.The function then returns the total number of matches(vowels) found.
12+
This brings return statements to mind as they simply stop the execution of
13+
a function and return a value from that function.
14+
*/
15+
16+
// #1.Using Iterative approach
17+
18+
const vowel = ["a", "e", "i", "o", "u"];
19+
20+
function vowelcnt(text) {
21+
let counter = 0;
22+
23+
//Loop through text to test if each character is a vowel
24+
for (let letter of text.toLowerCase()) {
25+
if (vowel.includes(letter)) {
26+
counter++;
27+
}
28+
}
29+
30+
// Return number of vowels
31+
32+
return counter;
33+
}
34+
35+
console.log(vowelcnt("i love you"))

0 commit comments

Comments
 (0)