22.08 · Final JavaScript challenges / Practice · 8 min
Count uppercase vowels too
Visit every character and count each English vowel, regardless of its case.
Activity 8 of 8 in Final JavaScript challenges
JavaScript Basics / 22.08
Count uppercase vowels too
Not started
Visit every character and count each English vowel, regardless of its case.

Count English vowels without losing repeats
Work through 5 focused steps. Read the explanation, type each requested change and check it before moving on. Your own code carries forward.
The mini-lesson opens in a new tab. Your own code carries forward; each step has a focused check and an optional hint.
Start mini-lesson(opens in a new tab)5 steps · Saved work · Instant feedback
YOUR TURN
Count uppercase vowels too
Repair countVowels(str) so it returns the number of vowel occurrences, ignoring case. Count only English a, e, i, o and u; y and accented letters are outside this exercise. Keep all three calls: hello returns 2, AEIOU returns 5 and rhythm returns 0. Count repeated vowels individually. Do not log inside the helper, change the input or hard-code the three results.
2 5 0
Keep the starting inputs. Print these lines in this order, without extra output.
Edit JavaScript, then run it. Check Challenge shows which output checks pass or need a fix. Word wrap is enabled.
Ready to checkRun the checks to see your results here.
Your check results
Work in VS Code instead
Copy the starter into a file named practice.js in VS Code. If Node.js is installed, open the terminal in that folder and run node practice.js. Compare the output with the task above. Automated challenge checks are available in the browser editor.
function countVowels(str) {
const vowels = "aeiou";
let count = 0;
for (let i = 0; i < str.length; i++) {
if (vowels.includes(str[i])) {
count++;
}
}
return count;
}
console.log(countVowels("hello"));
console.log(countVowels("AEIOU"));
console.log(countVowels("rhythm"));Need a nudge?
Compare in one case
The reference text aeiou is lowercase. Convert each character to lowercase before passing it to includes. The original string is unchanged.
Count every matching occurrence
Increase count for every character that matches. Repeated vowels still count; a set of unique letters would answer a different question.
One possible solution
Your code may look different and still be correct. Compare the approach with your own.
includes performs a case-sensitive search. A lowercase copy lets A match a while preserving the original input. hello has e and o; AEIOU has five vowels; rhythm has none under the stated English a/e/i/o/u rule. Empty text also returns 0.
function countVowels(str) {
const vowels = "aeiou";
let count = 0;
for (let i = 0; i < str.length; i++) {
if (vowels.includes(str[i].toLowerCase())) {
count++;
}
}
return count;
}
console.log(countVowels("hello"));
console.log(countVowels("AEIOU"));
console.log(countVowels("rhythm"));Ready to try it?
Practice in your browser and see your results.
Progress details
Have a question?
Ask the Code Zone community.
Ask a question in The Code Zone (opens in a new tab)Continue learning

7 days freeTry The Code Zone
THE CODE ZONE COMMUNITY
Your next step is easier together.
Try the community free for 7 days.
No charge during your trial. Choose your plan on Skool.
- Ask questions and get support in the community
- Watch every course video walkthrough
- Find a study buddy in the 24/7 study room
Make the most of your trial with Premium.
Choose Premium on Skool to try Thursday live help sessions. Bring your questions, work through code, and get unstuck together.
Scheduled Thursdays in Eastern Time. Check the Skool calendar for your local date and time.
Have a website account? Sign in