Learning Challenge
Control Flow Using Conditionals
Vowel Counter
Write a function, countVowels(word)
, that takes in a string word
and returns the number of vowels in the word.
Vowels are the letters “a”, “e”, “i”, “o”, “u”.
Question
What is wrong with my code I have been working on it for days.
What I’ve tried
I have tried searching on Stack Overflow for code that can accomplish the task.
I have found code, but the code I found on StackOverflow uses methods I have not learned yet.
Screenshots
My Code Solution
Here is the pseudocode I have written myself, I am still working on the code.
//Find out the number of characters in the word
//Look at each character in the word and test to see if its a vowel
//If yes then move to the next letter in the word and repeat the test
//When all letters in word have been tested for a vowel match
//the job is complete print the number of vowels in the word
### What I’ve tried
function count Vowels(word) {
const vowels =[“a”,“e”,“i”,“o”,“u”];
let vlength = vowels.length;
let text = word;
let tlength = text.length;
let index = 0;
Do While (index < tlength)
{
if (text[index]===vowel[index]);
{
index++ // increment the index counter by 1
vowelcnt = vowelcnt + 1 // increment the vowel found count by 1
}
}
countVowels(“abcdefg”)