-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathproblem62.js
28 lines (22 loc) · 887 Bytes
/
problem62.js
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
/* =====================================================================
------ Programme for calculating Total vowels and consonants --------
===================================================================== */
const countVowelsAndConsonants = textInput => {
const allLetters = textInput.toLowerCase();
const vowels = 'aeiou';
let vowelsCount = 0 ;
let consonantsCount = 0;
for ( let i = 0; i < allLetters.length; i++){
let letter = allLetters[i];
if(/[a-z]/.test(letter)){
if(vowels.includes(letter)){
vowelsCount++;
}
else{
consonantsCount++;
}
}
};
return {yourInput: textInput, totalVowels: vowelsCount, totalConsonants: consonantsCount};
};
console.log( countVowelsAndConsonants("[email protected]"));