Vowel Counter Javascript

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”.


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.


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




hi Jose,
to start with,

  • please review you function name for the extra space (1st line, last line)

  • please review “function” structure. your function is missing something fundamental. Hint: where is your output ?

  • the code you shared is missing a " } ". please review which one is opened but not closed.

  • please run your code, and see what you get. if you see a “syntax error” in the console, it means you have a syntax issue. please review your syntax for correctness. ie/ semi columns, opening and closing brackets…

good luck :slight_smile: