-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathvowelCounter.js
More file actions
78 lines (64 loc) · 1.9 KB
/
vowelCounter.js
File metadata and controls
78 lines (64 loc) · 1.9 KB
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
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
/*
You are in an English class, your teacher tells the class that vowels are the glue that hold words and sentences together.
They want to make sure you understand the importance of vowels in a sentence.
You are given example sentences and are to give a total amount of vowels that are in each sentence.
Task:
Write a program that takes in a string as input, counts and outputs the number of vowels (A, E, I, O, U).
Input Format:
A string (letters can be both uppercase or lower case).
Output Format:
A number which represents the total number of vowels in the string.
Sample Input:
this is a sentence
Sample Output:
6
Explanation:
There are 6 vowels in the sentence: this is a sentence.
*/
vowelCounter = (x) => {
var myArray = new Array();
myArray = x;
// console.log(myArray);
myArray = myArray.toLocaleLowerCase();
// console.log(myArray);
myArray = myArray.split("");
// console.log(myArray);
// console.log(myArray.length);
let k = 0
for(let i = 0; i< myArray.length;i++){
// console.log(myArray[i]);
switch(myArray[i]){
case 'a':
k++;
break;
case 'e':
k++;
break;
case 'i':
k++;
break;
case 'o':
k++;
break;
case 'u':
k++;
break;
default:
break;
}
}
console.log(k + ' : Total Vowels Counts in the Input');
}
vowelCounter("this is a sentence");
vowelCounter("How are you");
vowelCounter("Can I know your name?");
vowelCounter("What can I do for you?");
vowelCounter("JavaScript is awesome");
/* OUTPUT */
/*
6 : Total Vowels Count in the Input
5 : Total Vowels Count in the Input
7 : Total Vowels Count in the Input
7 : Total Vowels Count in the Input
8 : Total Vowels Count in the Input
*/