forked from diwakar1593/JavaScript-Problem
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcount_vowels.js
More file actions
25 lines (20 loc) · 766 Bytes
/
count_vowels.js
File metadata and controls
25 lines (20 loc) · 766 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
function countVowels(inputString) {
// Convert the input string to lowercase to make it case-insensitive
inputString = inputString.toLowerCase();
// Initialize a variable to store the vowel count
let vowelCount = 0;
// Define a string containing all the vowels
const vowels = 'aeiou';
// Loop through the characters in the input string
for (let i = 0; i < inputString.length; i++) {
// Check if the character is a vowel
if (vowels.includes(inputString[i])) {
vowelCount++;
}
}
return vowelCount;
}
// Example usage:
const testString = "Hello, World!";
const numberOfVowels = countVowels(testString);
console.log(numberOfVowels); // Output will be 3 (e, o, o are vowels)