thecodezone.
The Code Zone
Short steps, at your pace · Free lessons and practice · Member video walkthroughs
Save your next small win.

Checking your account…

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

All courses

JavaScript Basics / 22.08

Count uppercase vowels too

Not started

Visit every character and count each English vowel, regardless of its case.

More options
Rob compares an uppercase AEIOU input using a lowercase copy and counts five, while rhythm has zero.
Rob’s comic strip · Final JavaScript challenges

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.

Expected output
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.

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.

Code example
example.jsjavascript · example
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.

Replace your editor code?

Your current work will be replaced. Choose Cancel to keep it.

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

ONE STEP FORWARD

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.